From patchwork Mon Oct 6 23:21:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 543 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=1759793020; bh=WzKC1OyxCIgx+K7BsGQj7DO6fcHGu4XfXz6JijhIHP4=; 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=PIbld0EhN+Y59Y5EoZmxeBgbULr9v8h1O9cL8DMCOQ5uz1uxCJiIk/s0Ujv8iwvMR q2MPRU94Mb7qmde1yLGh8bgGb8zXb1Qg2DedS5YGHtFnWnuYUNxgnTNKZ93Dfbogyj /mAFiRT4hdJwOj4uFm+vxEk7Lsxb+RqpluD8Kac7CQ1yCZrBnR0M0JpUEoWKwfVdMN OdHxCwTBLDtcIAR1+A8qXfc157K8tfYlW5beGNJbMfdFl/OFatA0WhozRNn1xO6vgS gUOH1QgVe8gP9ptnH6bl7ZB7V0GaM0NfKK55N7ZBcMJFt1fVvMvD5YeVf+N4xSN4vu K+7Z/Zi89bq/A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A146C67F5A for ; Mon, 6 Oct 2025 17:23:40 -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 gBbzR9aAiECp for ; Mon, 6 Oct 2025 17:23:40 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759793020; bh=WzKC1OyxCIgx+K7BsGQj7DO6fcHGu4XfXz6JijhIHP4=; 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=PIbld0EhN+Y59Y5EoZmxeBgbULr9v8h1O9cL8DMCOQ5uz1uxCJiIk/s0Ujv8iwvMR q2MPRU94Mb7qmde1yLGh8bgGb8zXb1Qg2DedS5YGHtFnWnuYUNxgnTNKZ93Dfbogyj /mAFiRT4hdJwOj4uFm+vxEk7Lsxb+RqpluD8Kac7CQ1yCZrBnR0M0JpUEoWKwfVdMN OdHxCwTBLDtcIAR1+A8qXfc157K8tfYlW5beGNJbMfdFl/OFatA0WhozRNn1xO6vgS gUOH1QgVe8gP9ptnH6bl7ZB7V0GaM0NfKK55N7ZBcMJFt1fVvMvD5YeVf+N4xSN4vu K+7Z/Zi89bq/A== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 918BD67EE4 for ; Mon, 6 Oct 2025 17:23:40 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759793019; bh=PoeJHgx2awLLeGclEJ3V6KiDsG2u7+ELAJ7QSmdZjyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZdI19xpPqu6+8tfdDu+UQT7TP1snyoOYr6w1fC+pTN6bHcmC4shtFFNBT7yKNpzNt bGYk22KfpoWR9r3kBlHpM66htPOn2JrfULtkDtj7jBt6ZUrC0kc+Gk7HHeFv5835L4 FR7DTVQpMeQEDD14MSOwVwkhkHVX0xBlnbbx/pGxoOCdlyxQTt1PMTNTYo49SR6oe/ WNM6shiNYAIs+q2uyGMT/uibz0dmG61ksL2InC4Ch9TJ8i/YclEtDWSPngKtgfv4Sp QykG2ubx8lSNeYVLZd2qSCPmw8Ye0+XvcxafOw1OX2G2ODtKdp0cqXlVVZzx0texxQ gaR3KTxdDQdOQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EF89467E07; Mon, 6 Oct 2025 17:23:39 -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 VD1UDRGBVYl7; Mon, 6 Oct 2025 17:23:39 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759793014; bh=C6iwmF2hEIS/4EBYRsWalpM3cwMO5MP4dsq5XGYf+Fw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QKQ/9smKjP5Z70oqL6hH80MQG5AwoCc78xWDtiWiePx+TH+5rXoMDy8rqH+6feWLx JsvmOVNk7/0ZoU+7wTmZBmSqYCMlL5cqriem2Zz3FfyXQoFmoLPrgJ44JbK0iIIv7e VMNzJx4CZCTGL2ZbNVgJ8Cxli1f2dTAqvVN/hcPbuac1ZLrcgHwCbBoe6PeqN5U9s5 eXYmst1wy49bRI2LzVtl8WtWpEfdpzvVGKmXZYQmRkYJEKLPUTe1do6CvcDiTM5aOL Ypi7PIsAsam8EQd4eCgOfgnXqYeGwFFshsRhS/EMadmNLXxnehkXuXvoXTxYKjxmZ9 UAyzxZE0xvD6g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0661D67DB4; Mon, 6 Oct 2025 17:23:33 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 6 Oct 2025 17:21:55 -0600 Message-ID: <20251006232236.2091941-14-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: CZRJCVG6TQUER6MIQRUAH22VFHNHC5VG X-Message-ID-Hash: CZRJCVG6TQUER6MIQRUAH22VFHNHC5VG 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 13/17] efi: mouse: Move button handling 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 Split out the code that handles button presses into its own function, since efi_mouse_get_event() is already quite long. Signed-off-by: Simon Glass --- drivers/input/efi_mouse.c | 62 ++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/drivers/input/efi_mouse.c b/drivers/input/efi_mouse.c index 974c7e9fe1c..3e9ec370a50 100644 --- a/drivers/input/efi_mouse.c +++ b/drivers/input/efi_mouse.c @@ -39,6 +39,44 @@ struct efi_mouse_priv { struct efi_event *timer_event; }; +/** + * get_button_event() - Check for button-change events + * + * @priv: Private data + * @new_buttons: New button state + * @event: Event to populate if button changed + * Return: 0 if button event found, -EAGAIN if no button change + */ +static int get_button_event(struct efi_mouse_priv *priv, int new_buttons, + struct mouse_event *event) +{ + struct mouse_button *but = &event->button; + int diff = new_buttons ^ priv->old_buttons; + int i; + + if (new_buttons == priv->old_buttons) + return -EAGAIN; + + event->type = MOUSE_EV_BUTTON; + /* Find first changed button */ + for (i = 0; i < 2; i++) { + u8 mask = 1 << i; + + if (!(diff & mask)) + continue; + + but->button = i; + but->press_state = (new_buttons & mask) ? 1 : 0; + but->clicks = 1; + but->x = priv->x; + but->y = priv->y; + priv->old_buttons ^= mask; + return 0; + } + + return -EAGAIN; +} + static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) { struct efi_mouse_priv *priv = dev_get_priv(dev); @@ -81,27 +119,9 @@ static int efi_mouse_get_event(struct udevice *dev, struct mouse_event *event) new_buttons |= 1 << 0; if (state.right_button) new_buttons |= 1 << 1; - - if (new_buttons != priv->old_buttons) { - struct mouse_button *but = &event->button; - u8 diff = new_buttons ^ priv->old_buttons; - int i; - - event->type = MOUSE_EV_BUTTON; - /* Find first changed button */ - for (i = 0; i < 2; i++) { - u8 mask = 1 << i; - if (diff & mask) { - but->button = i; - but->press_state = (new_buttons & mask) ? 1 : 0; - but->clicks = 1; - but->x = priv->x; - but->y = priv->y; - priv->old_buttons ^= mask; - return 0; - } - } - } + ret = get_button_event(priv, new_buttons, event); + if (!ret) + return 0; /* Check for movement */ if (state.relative_movement_x || state.relative_movement_y) {