From patchwork Tue Oct 7 17:05:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 561 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=1759856818; bh=LquCRvmJ36LAIO4VdS6odX+duYUvtADKcHWLFLxwI38=; 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=MQsMOZY7y/WO5ZYEiXVj+RNQPwEhgS3HiddKqMbJrsv3l6rufDs2MQie4ewGH6xn5 2d9MxRLkiU6RiT0oa8eZ5l1Glav9i/Rvx4SKfJUs9m6Uec1wxmpCnFuTPXvxY6a0Nz mGBboEafPuAXWxuEsfweB6qepCIunautseAUid07SdXEkX4Tgaqgb/f++iWO0NvNdR jBJ3IwzNIIbR23QnUdXWvumBt+e086vjwXSOO/Ut7XQi7gzWh+zGDf5y03e6RmY8oL l19ASmvKpWMGGOEdv+iN5KqtM5C0ZLr8Rn9Kuwh6PBwASBAYAOg8fPjtrbOHgQl0/B M3Jh0fHJ+kmSA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EAF8667F6C for ; Tue, 7 Oct 2025 11:06:58 -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 l258R3nQrWWj for ; Tue, 7 Oct 2025 11:06:58 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856817; bh=LquCRvmJ36LAIO4VdS6odX+duYUvtADKcHWLFLxwI38=; 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=NU12JiWZWfIjrGNxJCcGvWyD84jcg5yUafwfi/2pdmsr8rNXopVX8qNt+P6zvp3XI JCaW5dLRQdriN9JX6KEnCgXT/VkdjB712S7EN9VGxJGP5N7Tlijr//Z2Wjoyyh4eiu zEhkc5Kxa817CicWTR3l6LX9U/vY680waFPsu3U8Osz9aldFtVrwx+kuSL6pJWzdm3 MRZ6ZUk298gKVU2ePAc5J9TagYDoSo2busWCPGmVraxsxVY5JKMwgq6QQog4Uyrob1 sSrzLG84En2TzXYNyvbv/bfY3F7HBSZtfqTZ4zuTxSNJTHRNjR9Q9jPm2Lkry/MUmg whcCiFO7lbzMA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1CBF167FF8 for ; Tue, 7 Oct 2025 11:06:57 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856815; bh=NCZLOex5b5PRsntdMuElUqwOSME6Dh7N+EQAeEG4Nrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cva6qhfCFiBEWYLQCHJhDHJMHsbzv8jRhCOuIZE/PbN3zcNW7KN0zd86Wv60+ubUz 0VWpUScJOa1b1yEeBnnjN62oaeUR4QKmIQlgfS71fgmjuVJnlNQ+o5etNonUtubOul E5IlmP2rNfq2lQjH3a94dwdrFu3yWv+IY5pvZsM4BBCehr40X5merKAYjz7/rFudPo 2gui7d6qpF3q7LhXi8mesbh/F1MpT6+oY2AyeSQODvu3FCCuExll7hvnmtwlRCvyY0 gHngPVfhKYu9xf6DlNmW+ymx1ZqF8D+tE0IHh+lWCJCDVdb8cHN6cP9rAt9bDAd1fN PCH7cTr+ZVpzg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9380667EE5; Tue, 7 Oct 2025 11:06:55 -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 kj_2qxydjUOo; Tue, 7 Oct 2025 11:06:55 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856813; bh=NqIAjw24q51NWywgsWfP8KTyN+2xkB2UC1OSskwRLM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZ2LLbxkhXi5IMzYrhs48ddFNXAop3JwQrigQ1NTO1w04PXYr8bGf6b0BYCHpCxlt +37E3NZJ5kGLHysi8ncp4gJu89VZBBuMz7EcYQHzJSC1WvshTvnLpCoIZkeTAEu1mn M6XQQf+Plq84mfNTJEeQ9FBKJMjxcaV0kW2EWT9chzCOJK3PpkU26HIa9DjIiS/viC Qsh3tMIPQ2WipXzNW3K6beyfz/H9jb4UkH3kPztl8+G2NU4LxaKNk6/iVk0Jne8CmM cicQQj0BjTchVTImFUffoTNcLvCGFMyr2VvfMJ2EaWhEk3EP3e8sSyETk9No//sL/P ugDrfhqBecr0A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 75C5A67F1E; Tue, 7 Oct 2025 11:06:53 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Oct 2025 11:05:29 -0600 Message-ID: <20251007170549.541981-16-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: YNZRQL6LYHQINJQ6VBCKJNLUEKR4NXVG X-Message-ID-Hash: YNZRQL6LYHQINJQ6VBCKJNLUEKR4NXVG 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 15/20] 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 --- (no changes since v1) 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 077e2148da9..5fdf6979b8f 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; }