From patchwork Tue Oct 7 17:05:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 562 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=1759856824; bh=ryocBSIfR3GgyA3+WTiPI9J+QySYHNnoqLDzLH2rLHI=; 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=VFQQaOIhbEUZbleKuEhhY2cJfKt3ZNW6VFlNNQCWX9N+M0P/atysXusCouaMJkXfx K4m/0fbwbY4mwB3Q/R+JKt4gDFb+IQJhUdtykYQGSPJEsxXFEf7lzoy7VMlLuw3Pp1 Q0LNTkmyRgoNq8j4gUYMAjwbpJEK1NclPz+tSBfX65embm1THGz6n1FYr6CBsU9W1j vuUCS9An4kockEimkxs4LYCdA0zyjYhxiIcRCGQF1NfjH6Tl19a9HmJo/3rvTE9E1f 9PI3cmbiBFMuHMRyaw5uEHOtGn9UDUJi4vqswEx6ytsXaxf1g/pwU26pEBLRP1mJEI S/PMOl7XGTWlw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0F4FE67F74 for ; Tue, 7 Oct 2025 11:07:04 -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 qaX5YxtGxsaJ for ; Tue, 7 Oct 2025 11:07:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856823; bh=ryocBSIfR3GgyA3+WTiPI9J+QySYHNnoqLDzLH2rLHI=; 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=qSLZCeK+JusAoih31LNVi5FZJt8QdbPe8vKwsZLl+V7vNdUyNICaa9lESn2YTTXmy 747S+chbvCvYp2Vk68EnzH9ePhoC83Z/WatXzofp8gRw82E0tCEk2E/gblOh7aZMyY C8Ek/ExqkvQHd7IyrPqV/Vw3xRarTaRhJHvWdeKLUlpjLcmhNuFBI1O4XSiaXFsahA x+aF00k4uD9ExykbyCuVMiD/rrocLKaNWMkMRcZ4ezNX9IYV10baRVsSmZzDch82N6 pQcITQ5k9mJHLbz+NhDapi1IZfnNk/OwknkCqCYT1aa+2fRd5XbKm0cX1ocgbd1UJI vIWFz/P8xDm9Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EFC7367F71 for ; Tue, 7 Oct 2025 11:07:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856821; bh=ARGxfD14pHuHHxBBg3P/uIioFJFRTsYMyxcXyv1Lceg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BOpZ7tenC81W2pGItWV1YdpSU8S8MpcWoGBSo9RavNuWTs2JSa9Wu5Zk4YILXfk28 jrq1MlonEABFXqaaijU7dfwxKZnGSAebIkArAPKUzxpsuWNyG6fdnVafn57cCEzf5h ALuFRwpqVCVoEdcCLREDLx3eFc0gBMqqbMO3P1uxXctn2aelGSbkCv1CEoJgGu4SiA E7RfCH/j0dQp9bkfJTsVtwLMxkvMto2Bx3uIy1DMu965guY/lLCtbvshuFDzSYtWZs 5Mkre646wh9JrDTs2wiMgX7aC/IEK6blosNkcwOiQs+Rvzb0wutNFM+JWfmhjy6Dh5 JMtcoljWjx9Cw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 40ED567DD0; Tue, 7 Oct 2025 11:07:01 -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 9tPB7nXuzwNS; Tue, 7 Oct 2025 11:07:01 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759856816; bh=JMMrVggy6+1aiOr9e2jaGtZ+hJvJmJGo3gvRLah9YkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bXQJStQ4DOBOEqKOQ5W038KFyOPEkEinVw7R+US7foFmP0BfBn9vradI0nhgu6QWV 2GYfTJSDIR7fZkz4DKmVJC8pJM0Rg7EvOv+dDW2/WX7yx77/v6P6CnssQdbUfhORy7 g4thi5DfXsMEmguJ/npNboxWkwnjh08Leak0ZDK11ITIF+x11/XQ9r/CcMUuKZ9+qI yhnsa2HRmOCJZ2sOXAyQosDTbN79o2VjR8r834W+fGXgno0CDEahrO3v0MDZkATTaY f5BeOdVyjS+8za5qGoNO7PJeCU6GvtTTL0nGfJgjEre9j1m5B8BMudsQxcfELsNp57 6U+x1g4ulOaAA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D13A867F1E; Tue, 7 Oct 2025 11:06:55 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 7 Oct 2025 11:05:30 -0600 Message-ID: <20251007170549.541981-17-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: TJVQ5IO2CAJTJAFRLXPDAAHTUITEZ4NG X-Message-ID-Hash: TJVQ5IO2CAJTJAFRLXPDAAHTUITEZ4NG 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 16/20] 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 --- (no changes since v1) 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 5fdf6979b8f..5badbfab066 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->pressed = (new_buttons & mask) ? true : false; + 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->pressed = (new_buttons & mask) ? true : false; - 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) {