From patchwork Tue Feb 11 13:39:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Werner Sembach X-Patchwork-Id: 864270 Received: from mail.tuxedocomputers.com (mail.tuxedocomputers.com [157.90.84.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4114244196; Tue, 11 Feb 2025 13:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=157.90.84.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739281205; cv=none; b=JR2tMTXELAB1NsKlVmxbC57F1MkVJiWpMuHrL/Pewy6kpFo9TQLTzmUgXBrzU8r2LF3hHq0ViifKMD5tTIHMiviyz4MK3Nnjb+p0j02lXewRUIJKzMfHJS5t+Pu8Az08jYC2VbPYQ/GRhQD71zEeEekp7S2LiH9lKgvu/CMLDkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739281205; c=relaxed/simple; bh=MzCHS4xcpR6oKnwNF5bnd1dPG4rnXwLyPn8vttdj214=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DMSf/SeyC2WGgWYAUg12YLIZk8wz/OLrwA7182JjenZ4EHBbQEblWu9+sPLQb2KxQgkq6W+vQARN4gx39fHHfZYwkz3cGkR6rF8Myqoshbpn0DrRKtWaKBM5xqAVf2FCx+vLJzoCdj9aiyHils6HO6gyGswdzeoD3ydWJ47Jazk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tuxedocomputers.com; spf=pass smtp.mailfrom=tuxedocomputers.com; dkim=pass (1024-bit key) header.d=tuxedocomputers.com header.i=@tuxedocomputers.com header.b=LejbcdjA; arc=none smtp.client-ip=157.90.84.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tuxedocomputers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxedocomputers.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tuxedocomputers.com header.i=@tuxedocomputers.com header.b="LejbcdjA" Received: from wse-pc.fritz.box (pd9e59260.dip0.t-ipconnect.de [217.229.146.96]) (Authenticated sender: wse@tuxedocomputers.com) by mail.tuxedocomputers.com (Postfix) with ESMTPA id 6FBFF2FC004D; Tue, 11 Feb 2025 14:39:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxedocomputers.com; s=default; t=1739281193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YB3kOHzvyAH2tkfntNwIJh9bjqnKflyo3rJ0J7XtYAg=; b=LejbcdjAU8pD0rYzMhKZKn4haEWqKG5eIgAoipIC//nWAIX908c2QHyxT7Q7uY4pmRs4Wt 11xO+TYOEs8CxTLZEfbnEF2PKEB1fEPKbMB2anehDQPkbrZq2mZAZbRdRxqCBYYxmTfarO 8+m3Nu40xDVl9Tyfb+IF4suW9BNyosk= Authentication-Results: mail.tuxedocomputers.com; auth=pass smtp.auth=wse@tuxedocomputers.com smtp.mailfrom=wse@tuxedocomputers.com From: Werner Sembach To: Jiri Kosina , Benjamin Tissoires Cc: Werner Sembach , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] Add functions for HID drivers to react on first open and last close call Date: Tue, 11 Feb 2025 14:39:05 +0100 Message-ID: <20250211133950.422232-1-wse@tuxedocomputers.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds a new function to the hid_driver struct that is called when the userspace starts using the device, and another one that is called when userspace stop using the device. With this a hid driver can implement special suspend handling for devices currently not in use. Signed-off-by: Werner Sembach --- drivers/hid/hid-core.c | 9 ++++++++- include/linux/hid.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 4497b50799dbf..283917a79ac86 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2392,6 +2392,9 @@ int hid_hw_open(struct hid_device *hdev) ret = hdev->ll_driver->open(hdev); if (ret) hdev->ll_open_count--; + + if (hdev->driver->on_hid_hw_open) + hdev->driver->on_hid_hw_open(hdev); } mutex_unlock(&hdev->ll_open_lock); @@ -2411,8 +2414,12 @@ EXPORT_SYMBOL_GPL(hid_hw_open); void hid_hw_close(struct hid_device *hdev) { mutex_lock(&hdev->ll_open_lock); - if (!--hdev->ll_open_count) + if (!--hdev->ll_open_count) { hdev->ll_driver->close(hdev); + + if (hdev->driver->on_hid_hw_close) + hdev->driver->on_hid_hw_close(hdev); + } mutex_unlock(&hdev->ll_open_lock); } EXPORT_SYMBOL_GPL(hid_hw_close); diff --git a/include/linux/hid.h b/include/linux/hid.h index cdc0dc13c87fe..3b7db4eb3f2f6 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -790,6 +790,8 @@ struct hid_usage_id { * @suspend: invoked on suspend (NULL means nop) * @resume: invoked on resume if device was not reset (NULL means nop) * @reset_resume: invoked on resume if device was reset (NULL means nop) + * @on_hid_hw_open: invoked when hid core opens first instance (NULL means nop) + * @on_hid_hw_close: invoked when hid core closes last instance (NULL means nop) * * probe should return -errno on error, or 0 on success. During probe, * input will not be passed to raw_event unless hid_device_io_start is @@ -845,6 +847,8 @@ struct hid_driver { int (*suspend)(struct hid_device *hdev, pm_message_t message); int (*resume)(struct hid_device *hdev); int (*reset_resume)(struct hid_device *hdev); + void (*on_hid_hw_open)(struct hid_device *hdev); + void (*on_hid_hw_close)(struct hid_device *hdev); /* private: */ struct device_driver driver; From patchwork Tue Feb 11 13:39:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Werner Sembach X-Patchwork-Id: 864681 Received: from mail.tuxedocomputers.com (mail.tuxedocomputers.com [157.90.84.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C409A243965; Tue, 11 Feb 2025 13:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=157.90.84.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739281205; cv=none; b=XnqtXH/ItwTkC5T97fa5aArsncCNIgJzv96HHualADEQsPQHCTw60lcNmJu2XQSeaKyAatQg0fFYnA3RNLKim2e3vxliFNI7GUkZPDrHz0kZJJ00xig2H0/1dJ2DOirBG1yb/ElFbiVyhE2f+lA9ifyaJAzYS2d7CRufjgada34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739281205; c=relaxed/simple; bh=xWgNXPNKZM03oUis7O6rUJXGQZfLIM7VkOP+M2x6oOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RYoOtO34iZ0dwdlnfiFyI37fCiLHDT2QuOyRguriKC5LkzHfcUC8clAvc83v3En0hldVph409ju98aDnD3pThRSxmajIkbLeJw4VNGyAEILCbJziZ0jfEdgG1qFVXbt6WJXlIE9IQLxd5q7Z5pWH1x9JIXkDSyEroL1CPd1UyhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tuxedocomputers.com; spf=pass smtp.mailfrom=tuxedocomputers.com; dkim=pass (1024-bit key) header.d=tuxedocomputers.com header.i=@tuxedocomputers.com header.b=cQ9tbpEo; arc=none smtp.client-ip=157.90.84.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tuxedocomputers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxedocomputers.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tuxedocomputers.com header.i=@tuxedocomputers.com header.b="cQ9tbpEo" Received: from wse-pc.fritz.box (pd9e59260.dip0.t-ipconnect.de [217.229.146.96]) (Authenticated sender: wse@tuxedocomputers.com) by mail.tuxedocomputers.com (Postfix) with ESMTPA id 5E76B2FC0050; Tue, 11 Feb 2025 14:39:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxedocomputers.com; s=default; t=1739281194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4XL4YdXnK949uXLMtLZEecfF+8yrfks6KMpFtdAL3gA=; b=cQ9tbpEonawPU8Y7E9jssi4XMybXyt6ioGDvAgYc3DtzzU5wgEvbVOrESam/7uZoNbvWar rIKnLxrCE6rhUxLqK4dghZoPTjDWw9tN0x318qFcKs0BW3TQGJ2O8mgPS/nG0iPKSFxdIv R9GXRAgpjGt5JE0X5fbxsACfstKx1x0= Authentication-Results: mail.tuxedocomputers.com; auth=pass smtp.auth=wse@tuxedocomputers.com smtp.mailfrom=wse@tuxedocomputers.com From: Werner Sembach To: Jiri Kosina , Benjamin Tissoires Cc: Werner Sembach , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] Disable touchpad on firmware level while not in use Date: Tue, 11 Feb 2025 14:39:06 +0100 Message-ID: <20250211133950.422232-2-wse@tuxedocomputers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250211133950.422232-1-wse@tuxedocomputers.com> References: <20250211133950.422232-1-wse@tuxedocomputers.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using the new on_hid_hw_open and on_hid_hw_close functions to disable the touchpad on firmware level while not being in use. This safes some battery and triggers touchpad-disabled-leds hardwired to the touchpads firmware, that exist for example on some TongFang barebones. For a lengthy discussion with all the details see https://gitlab.freedesktop.org/libinput/libinput/-/issues/558 Signed-off-by: Werner Sembach --- drivers/hid/hid-multitouch.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 82900857bfd87..7289c04f47f17 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -1884,6 +1884,16 @@ static void mt_remove(struct hid_device *hdev) hid_hw_stop(hdev); } +static void mt_on_hid_hw_open(struct hid_device *hdev) +{ + mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL); +} + +static void mt_on_hid_hw_close(struct hid_device *hdev) +{ + mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE); +} + /* * This list contains only: * - VID/PID of products not working with the default multitouch handling @@ -2351,5 +2361,7 @@ static struct hid_driver mt_driver = { .suspend = pm_ptr(mt_suspend), .reset_resume = pm_ptr(mt_reset_resume), .resume = pm_ptr(mt_resume), + .on_hid_hw_open = mt_on_hid_hw_open, + .on_hid_hw_close = mt_on_hid_hw_close, }; module_hid_driver(mt_driver);