From patchwork Mon Oct 6 23:21:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 542 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=1759793017; bh=1Yxea/gbF6Xer5RrAMGeTXf5CgLdBKE4c9VlbUFxe10=; 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=eKfwoUKwgRbDtS1sVOco3vilbwCKpbNTPqzHlecYrjRKIYpcXlJwrnVH0dXLkbQRO qKlfA+LaYU61vKMpsJv9bZ9VgLsMSjLFF38TTaarcLLOEmNq31gWK+q7iFsRuqrECP 1BescUdA+H6Y4UI678ZFmkr+Vx5rg1HXcjOBMwfd6YpInwHVfLczme3dQBddtjVs0a r97Tbzb/nxU1kC71tO4U7uvqQqzKqPS6wOWtnvFWIDPBye6XCLzVWwDy/doPbBcL4d g8fODYUpm9SQX785QuBlI03vcw6grdr45qLZrCTuCUKZlsT/eKdtCW1PF/PHFjTggs m6FxpCE7OkjmQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A0DED67FB7 for ; Mon, 6 Oct 2025 17:23:37 -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 JC5vTKxQIyCb for ; Mon, 6 Oct 2025 17:23:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759793015; bh=1Yxea/gbF6Xer5RrAMGeTXf5CgLdBKE4c9VlbUFxe10=; 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=s1VmsqI1Pgx4SaZE9yDJVwfhOeZT6TUpCY+fQprGqZaaADgVdwTAYUaZZ7ZPwFxLO TMgzyYfD/qmzB1dI4k8ym0dhQML7np5940saIYuTkLtZs0VN5ZtMD+z/YF7UTJOAb1 nObQLLruHCnXoEsO8jWjZj7T4xZuEFQOx8K3XBRp4ifQjN9ivsWD95TqxRk6URDz5p zIGBjbrYSykMjvGulEz6eRBj9u45XdpU/NuUaFnJW5O/e+xQVIuCrjKomKlWd9CK1L DQuoI9ef1J6XVOAxpSsbYKCqrwCTAonJrXaq7C+i3gWXqTwf6iHvO5BTlQiE+qwI80 sOoOYklQ5LJRg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B30CD67FE0 for ; Mon, 6 Oct 2025 17:23:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759793013; bh=FcKQgZ1siJZwkz8PcgTYC6f7H2Df1iDq5J3SamBHMFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OR77fr+8UbgbJPP/IbzmNV6cvNV7/qiGJMiCsIMRbSemhJ06msnxu0x0nN2PGeHRO 9W4WkWOlpPVEJUQThyGEkm8b4zy6ytsH6RXAbz2B4UemN5stNxA4CA7Ibw8jVz+gHG w+X3iY5J/KLByeh3QLbJOnrzW5qH3fpeiGp8C4eU2gTFUC/2NREhv96kRfmIFOSyXG epsQ3ZaYJNVQT1CKbXtCDZG+0M+U5m737BCl2dw3VzCRVA10cJJ96IMESbIOgUqe8S gmx6W5aBZvnbSe6qDNyBf052xynWxmQbrwIMe76xVLhoUmqkCdv+IZda6blStXZfRi MBQgSx//5AHVw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B628067EE4; Mon, 6 Oct 2025 17:23:33 -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 qbhcg4Y8s4J2; Mon, 6 Oct 2025 17:23:33 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759793012; bh=crbD2YB8i9D+OT5fQqVHjyVtdtHhyvZaM+fdcIF74B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AICgPE4GNnMAjevllGxwFd4cwe4WwQNRPE2Sjd3lwybmSdPQ7lf6neuZPpqfZjBcq liCZkKZpQB2s9SYQe9Y/nrbz3GVbhWzK/ZnJPQ/841bfmP2FZ3WoLtipiglbiuzjTk j5HjFSh+PHeuUffBlGJeyRd/9M1hvdYJeAhZQY6/fa36CglnXmlxjZa+cNOaLet/wL xn/55V1Kuy7YHCYJPcDyxP3sHzcikikizaHLper2UTVkpTYhFkQsOCdm7BJ+zBmSzM ZWXtcVPKR5CxlTpcpwWruFVdtUTeGxUGKh0b4GXR22X2FstBZDGfbG+6kjygdiEdzv LRIPPbdKu6PJA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F08A367DB4; Mon, 6 Oct 2025 17:23:31 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 6 Oct 2025 17:21:54 -0600 Message-ID: <20251006232236.2091941-13-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251006232236.2091941-1-sjg@u-boot.org> References: <20251006232236.2091941-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: V64Z3GL5W7P7LCULAG2ZLZ6TUKDYQD32 X-Message-ID-Hash: V64Z3GL5W7P7LCULAG2ZLZ6TUKDYQD32 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 12/17] efi: mouse: Move simple-pointer code into a function 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 In preparation for supporting an absolute pointer, move the setup of the simple pointer into its own function. Rename 'pointer' to simple and last_state to simple_last. Take this opportunity to add comments for struct efi_mouse_priv since it will be less obvious once the new support is added. Clean up some unnecessary cruft in the remove() path. Signed-off-by: Simon Glass --- drivers/input/efi_mouse.c | 103 +++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/drivers/input/efi_mouse.c b/drivers/input/efi_mouse.c index 84347951f62..974c7e9fe1c 100644 --- a/drivers/input/efi_mouse.c +++ b/drivers/input/efi_mouse.c @@ -14,9 +14,24 @@ #include #include +/* Maximum coordinate value for mouse position */ +#define MOUSE_MAX_COORD 0xffff + +/** + * struct efi_mouse_priv - Private data for EFI mouse driver + * + * @simple: Simple pointer protocol (relative movement) + * @simple_last: Last simple pointer state + * @has_last_state: True if we have a previous state for delta calculation + * @x: Current X position + * @y: Current Y position + * @buttons: Current button state + * @old_buttons: Previous button state for detecting changes + * @timer_event: EFI timer event for periodic polling + */ struct efi_mouse_priv { - struct efi_simple_pointer_protocol *pointer; - struct efi_simple_pointer_state last_state; + struct efi_simple_pointer_protocol *simple; + struct efi_simple_pointer_state simple_last; bool has_last_state; int x, y; int buttons; @@ -30,7 +45,7 @@ static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) struct efi_simple_pointer_state state; efi_status_t ret; int new_buttons; - if (!priv->pointer) + if (!priv->simple) return -ENODEV; /* Use timer-based polling approach like EFI keyboard */ @@ -41,8 +56,8 @@ static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) efi_uintn_t num_events = 1; events[0] = priv->timer_event; - if (priv->pointer->wait_for_input) { - events[1] = priv->pointer->wait_for_input; + if (priv->simple->wait_for_input) { + events[1] = priv->simple->wait_for_input; num_events = 2; } @@ -52,7 +67,7 @@ static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) } /* Get current pointer state */ - ret = priv->pointer->get_state(priv->pointer, &state); + ret = priv->simple->get_state(priv->simple, &state); if (ret != EFI_SUCCESS) { if (ret == EFI_NOT_READY) return -EAGAIN; @@ -117,63 +132,74 @@ static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) return -EAGAIN; } -static int efi_mouse_probe(struct udevice *dev) +/** + * setup_simple_pointer() - Set up simple pointer protocol + * + * @priv: Private data + * Return: 0 if OK, -ve on error + */ +static int setup_simple_pointer(struct efi_mouse_priv *priv) { - struct efi_mouse_priv *priv = dev_get_priv(dev); struct efi_boot_services *boot = efi_get_boot(); - efi_status_t ret; efi_handle_t *handles; efi_uintn_t num_handles; + efi_status_t ret; - log_debug("EFI mouse probe\n"); - - /* Find Simple Pointer Protocol handles */ + log_debug("EFI simple-pointer mouse probe\n"); ret = boot->locate_handle_buffer(BY_PROTOCOL, &efi_guid_simple_pointer, NULL, &num_handles, &handles); - if (ret != EFI_SUCCESS) { - printf("EFI mouse: No EFI pointer devices found (ret=0x%lx)\n", ret); + if (ret) return -ENODEV; - } - log_debug("Found %zu EFI pointer device(s)\n", num_handles); + log_debug("Found %zu simple pointer device(s)\n", num_handles); - /* Use the first pointer device */ + /* Use the first simple pointer device */ ret = boot->open_protocol(handles[0], &efi_guid_simple_pointer, - (void **)&priv->pointer, efi_get_parent_image(), - NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (ret != EFI_SUCCESS) { - printf("EFI mouse: Failed to open EFI pointer protocol (ret=0x%lx)\n", ret); + (void **)&priv->simple, + efi_get_parent_image(), NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret) { + log_debug("Cannot open simple pointer protocol (ret=0x%lx)\n", + ret); efi_free_pool(handles); - return -ENODEV; + return -EIO; } + log_debug("Using simple pointer protocol\n"); efi_free_pool(handles); + return 0; +} + +static int efi_mouse_probe(struct udevice *dev) +{ + struct efi_mouse_priv *priv = dev_get_priv(dev); + struct efi_boot_services *boot = efi_get_boot(); + efi_status_t ret; + + if (setup_simple_pointer(priv)) + return -ENODEV; + /* Reset the pointer device */ - ret = priv->pointer->reset(priv->pointer, false); + ret = priv->simple->reset(priv->simple, false); if (ret != EFI_SUCCESS) { log_warning("Failed to reset EFI pointer device\n"); /* Continue anyway - some devices might not support reset */ } - priv->x = 0; - priv->y = 0; - priv->buttons = 0; - priv->old_buttons = 0; - priv->has_last_state = false; - /* Create a timer event for periodic checking */ ret = boot->create_event(EVT_TIMER, TPL_NOTIFY, NULL, NULL, &priv->timer_event); - if (ret != EFI_SUCCESS) { - printf("EFI mouse: Failed to create timer event (ret=0x%lx)\n", ret); + if (ret) { + log_debug("Failed to create timer event (ret=0x%lx)\n", ret); /* Continue without timer - fallback to direct polling */ priv->timer_event = NULL; } else { /* Set timer to trigger every 10ms (100000 x 100ns = 10ms) */ - ret = boot->set_timer(priv->timer_event, EFI_TIMER_PERIODIC, 10000); - if (ret != EFI_SUCCESS) { - printf("EFI mouse: Failed to set timer (ret=0x%lx)\n", ret); + ret = boot->set_timer(priv->timer_event, EFI_TIMER_PERIODIC, + 10000); + if (ret) { + log_debug("Failed to set timer (ret=0x%lx)\n", ret); boot->close_event(priv->timer_event); priv->timer_event = NULL; } @@ -188,15 +214,10 @@ static int efi_mouse_remove(struct udevice *dev) struct efi_mouse_priv *priv = dev_get_priv(dev); struct efi_boot_services *boot = efi_get_boot(); - if (priv->timer_event) { + if (priv->timer_event) boot->close_event(priv->timer_event); - priv->timer_event = NULL; - } - if (priv->pointer) { - /* Protocol will be automatically closed when the image is unloaded */ - priv->pointer = NULL; - } + /* Protocol will be automatically closed when the image is unloaded */ return 0; }