From patchwork Tue Oct 7 17:05:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 566 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856837; bh=diFoa6jyzyoq/ZNRt9QrruAXrZVKyRtddZkzxKVT6lk=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=A8GTIgqEDl5SScQ09Kqyp2+SnYF9l0OODhppnQO7xaniT8jt1gg1iBOyKVfKH7T94 gDPRf2QEct1wkuqvY0XW/DLR6eQIyN+wONMSFv9jMMEPTtt1adm/zQMGvADCHDuIK2 W5xcQJHj4pntRShxfHsm2Xpd57300VA2l2JdbgFh95ZRRlnBlAkPClVLa834lJWQSW 3gg4NKdZNUayxuvthNZSHqw2gkhDZWdjzfBIW2nsgPLGP0HoffA+gU85w8u/7nOAb3 9AeqWVg2SABDMpdGeRXwW5o5qnS7dMQ0hPKcN0BWFWtUINU2cEnTymxvbmbRzSrKw0 X8AC7BfnDWkpA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E446367F6C for ; Tue, 7 Oct 2025 11:07:17 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id S0wms7F49czq for ; Tue, 7 Oct 2025 11:07:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856837; bh=diFoa6jyzyoq/ZNRt9QrruAXrZVKyRtddZkzxKVT6lk=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=A8GTIgqEDl5SScQ09Kqyp2+SnYF9l0OODhppnQO7xaniT8jt1gg1iBOyKVfKH7T94 gDPRf2QEct1wkuqvY0XW/DLR6eQIyN+wONMSFv9jMMEPTtt1adm/zQMGvADCHDuIK2 W5xcQJHj4pntRShxfHsm2Xpd57300VA2l2JdbgFh95ZRRlnBlAkPClVLa834lJWQSW 3gg4NKdZNUayxuvthNZSHqw2gkhDZWdjzfBIW2nsgPLGP0HoffA+gU85w8u/7nOAb3 9AeqWVg2SABDMpdGeRXwW5o5qnS7dMQ0hPKcN0BWFWtUINU2cEnTymxvbmbRzSrKw0 X8AC7BfnDWkpA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D3BC267F1E for ; Tue, 7 Oct 2025 11:07:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856835; bh=Kq5Toz9QMv8umKDP7MP+9XAk/FdHRo2KmadlSKbJuT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ePYTLezjImQP2zRaMePeBnCZbHzoiRUbxKKKT60keLVOJMoaTtCFeLeAQa+DXdZpX HTTof+y7F8hdlmOJF0f8nSIZj047LJlsq3x9wz/BHiFep+HIZzqGL6R3Jb6djrJJLf twvR1wmpRC1QrOgbj3fM60mx5sQHNUY9Zw2/fwUXLutDnDM8NAPFtRysXx//fgUl8x YMfxSccafBjhjGaN/fX0FuQOS8/uXfy++G6n6pFfKnQXkX2R75iXnd2+Z/aRZigIf1 TbrN0q2dX9ollvv1n9yDTFD6ckw/TTuQ63BllT6aCjJJCuzwH4zczwieuu688XfGXS yCPpIFgyC9G8w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2BE6267ECE; Tue, 7 Oct 2025 11:07:15 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id C8cvcTGFQsFR; Tue, 7 Oct 2025 11:07:15 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856828; bh=xYdXOFwsy/yiBANZHFiKJfJ6mSfaUpeik4PNKp5yRwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dHZYNiXOXSNcc8CSblbpW0S2BWiZQFgoSa64SJZJ/dkU3whKryJ5p9nNWTqaVC4Ru OlRtlzFHSoSMc0jV3nIiVDR53E9LlMnA9uh72wo2Lmn7/jaGP5JVWWu7Cttdd7vDWn AGLSXkJ/hBUNQFKW0tTKdebw0CAOJV83UGpLHNfmpUqOIce4oGAnfgiBJURLHKNIZj nqA33jOanaayhbeaveccqrAAfR1ioYfB0z+pizuAIMa4stUp5U4gNaZOusWpNGspIu cTOceRac5lac0jJqfz4YSlE/4EYhzf0dPrxNbC9Gc4V/mUJLSIyJOFvPjza6wZNTZk OGgVpJcZtq0+g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0CE4867DD0; Tue, 7 Oct 2025 11:07:07 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Oct 2025 11:05:34 -0600 Message-ID: <20251007170549.541981-21-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251007170549.541981-1-sjg@u-boot.org> References: <20251007170549.541981-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ABUMUXA5TQGGDNUYXANMND4MTYP4AZCY X-Message-ID-Hash: ABUMUXA5TQGGDNUYXANMND4MTYP4AZCY X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 20/20] efi: mouse: Scale the pointer to the display List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass If a display is provided to the mouse uclass, use it to scale the coords returned by the absolute-pointer protocol. Signed-off-by: Simon Glass --- (no changes since v1) drivers/input/efi_mouse.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/input/efi_mouse.c b/drivers/input/efi_mouse.c index b82a26c9885..087d135f675 100644 --- a/drivers/input/efi_mouse.c +++ b/drivers/input/efi_mouse.c @@ -13,6 +13,7 @@ #include #include #include +#include /* Maximum coordinate value for mouse position */ #define MOUSE_MAX_COORD 0xffff @@ -49,12 +50,14 @@ struct efi_mouse_priv { * get_abs_pointer() - Handle absolute pointer input * * @priv: Private data + * @uc_priv: Uclass-private data * @rel_x: Returns relative X movement * @rel_y: Returns relative Y movement * @new_buttons: Returns button state * Return: 0 if OK, -EAGAIN if no event, -ve on error */ -static int get_abs_pointer(struct efi_mouse_priv *priv, int *rel_x, +static int get_abs_pointer(struct efi_mouse_priv *priv, + struct mouse_uc_priv *uc_priv, int *rel_x, int *rel_y, int *new_buttons) { struct efi_absolute_pointer_state state; @@ -83,8 +86,28 @@ static int get_abs_pointer(struct efi_mouse_priv *priv, int *rel_x, log_debug("abs: rel_x=%d, rel_y=%d\n", *rel_x, *rel_y); } priv->abs_last = state; - priv->x = state.current_x; - priv->y = state.current_y; + + /* Update absolute position - scale to video display if available */ + if (uc_priv->video_dev && priv->abs->mode) { + struct efi_absolute_pointer_mode *mode = priv->abs->mode; + u64 x_range = mode->abs_max_x - mode->abs_min_x; + u64 y_range = mode->abs_max_y - mode->abs_min_y; + + if (x_range > 0 && y_range > 0) { + log_debug("abs: unscaled x=%llx y=%llx\n", + state.current_x, state.current_y); + priv->x = ((state.current_x - mode->abs_min_x) * + uc_priv->video_width) / x_range; + priv->y = ((state.current_y - mode->abs_min_y) * + uc_priv->video_height) / y_range; + } else { + priv->x = state.current_x; + priv->y = state.current_y; + } + } else { + priv->x = state.current_x; + priv->y = state.current_y; + } /* Extract button state */ *new_buttons = state.active_buttons & 0x3; /* Left and right buttons */ @@ -219,6 +242,7 @@ static int get_button_event(struct efi_mouse_priv *priv, int new_buttons, static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) { + struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev); struct efi_mouse_priv *priv = dev_get_priv(dev); struct mouse_motion *motion; int new_buttons; @@ -230,7 +254,8 @@ static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) * so we poll directly */ if (priv->use_absolute) - ret = get_abs_pointer(priv, &rel_x, &rel_y, &new_buttons); + ret = get_abs_pointer(priv, uc_priv, &rel_x, &rel_y, + &new_buttons); else ret = get_rel_pointer(priv, &rel_x, &rel_y, &new_buttons); if (ret)