From patchwork Mon Sep 15 10:46:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 303 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=1757933255; bh=GD0TEqodCBFZj6y7PyMQChY5jcPiOCTMBSQYUf5ks44=; 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=D6I8WmnhGseC+syjqyL+J4at8uEdYzkbYTk+pw0yeUdU+t8TS6m5uSa430abcSRFO deM68ZeI5bKCj7EB8O53mziRTgZwl8K2NRPksSaruvtot3ghEanPlKnB9kxV0f0vO+ wdcr7TXAqNGkd4lEUEIsjNwgyveaP9pVgJHlp15umY0+W2pRNGukVLAFfZytk/moHj dcSftkLX07ti0B7S1Nb1JK4h5Ma5Hs+XPZmyvgk1gZHM4r0Eq30eZOf5dkL1Yulh70 18yVP96yYS9C4KMsykQfTcw3LUUX6bXAc9VhjCU7nZqhN7K6BEvxuZ8NvA2ChaddyE QGJNPP0lnHPSw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6EDCC67A99 for ; Mon, 15 Sep 2025 04:47:35 -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 i69JpYATyiki for ; Mon, 15 Sep 2025 04:47:35 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933254; bh=GD0TEqodCBFZj6y7PyMQChY5jcPiOCTMBSQYUf5ks44=; 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=Jx38O9Dyxx9JV9x3nxeYSUGIFgC01YOADesk2wqKB9+l2i4ceRz+WGa0dxUyg/5n/ si5gVo2kjukS4AYFS1sZv9vwGiuQfXx83BgBXtiWjZdoIzyjP1O53OAAvzqE7yQloS 0oFQjwwu0Bim42Kc9u3XODU6tlDCDgi9CK4AWfWsho7DXjP1rfoVl/cjrBr2xzkpOT gKVFAsqqyx8UP7Ni1M2DECs/7M3DC10lRZCXGnHSquTfS4Tg7w2k6tzeY+b3BlaSdV K1YT2shiFEiwZPu0kRl8rh5ZPxirYpGGJv2+0bUE/561zbtdHaNJcQYQOUmtHfMv9l 9WfQp6oBHClRg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DD30A67B44 for ; Mon, 15 Sep 2025 04:47:34 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933252; bh=HcjFKArwUt7N1cVSggotzVo10hGKIjhDo1GrLaEeDzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0ZjTUw+7F8T5WSIEgfCwmcp/666lDR06XDaM+6GjQvgOJRu4a5g0aQXYar8chGo2 EOKBdFt3K3C/C/1GF5/97lqOZLLqHRkmxR+z/QQsh3BcLWl67pmKhRrt5CKifue/K1 pP+HJFa9cnHrA0hMEsc1VhMo5KN85cnjnOc4RFQJ3r4L9AMgcMDr6eNQOiEOqL2aoe KepSbbhH23GggFUqHEiXJDxXZRZaVHPAUf3YjEo/NSb9PSgkmWkR99ilwUBuK+3wom 0J8QnDG8RfUsZIMmjv5hC5CQEuntoXWPEjaTAAkz9UedUe+xg6sAOnuI7Tkk0XKV8D HD4xrNRrBqTTA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9E85D67A99; Mon, 15 Sep 2025 04:47:32 -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 XyGpPTfkOJiP; Mon, 15 Sep 2025 04:47:32 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933248; bh=HRngLDD2DdoybvKKUyAqfy8BcU2zq5s4sMdcBVttHhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwKwqVNWKcNgoKCplcGqUnVXhLHwgCNXALQRqy3ju/VBgrXwDMtd+LkiPoTSndiTI 6N86hc+1Igxs/uAfxG3Pze068e5UhhD/nPHZmweTWvrtuh4PG1O5/GVoDtAr2PuNn4 2ZOGj645zFrkaGEEs+1qSObInvZe2H7tAIfL85SE2z82g2WRnqYfJQOpSTXvV6F7r0 iiirzJCQ+dnR+EkLO8kYPl0DufNCo6ufPM2W8IGhozZHR3xT78w3L/RDLXotw6jitT c0cXXUi9U1PsvgjaXutAQyBBJaqQyuRO4UT+zeZiFccCb//PmSk1Z5drw4UzPNGMyM 9xorNIpG5NBTA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2336367B44; Mon, 15 Sep 2025 04:47:28 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 04:46:45 -0600 Message-ID: <20250915104705.937780-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915104705.937780-1-sjg@u-boot.org> References: <20250915104705.937780-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: HUZGM4ZB3O7MDSKKLNWED6UQL2ZCWXFS X-Message-ID-Hash: HUZGM4ZB3O7MDSKKLNWED6UQL2ZCWXFS 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 04/17] input: Add mouse support 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 When running a simple GUI it is useful to support a mouse. This is similar to what is provided in UEFI's boot menu. Add a simple uclass and a way to read the mouse position. For sandbox add a driver that reads the position from SDL. Disable input for the tools-only build, since it is of no use there and causes build failures. Signed-off-by: Simon Glass --- MAINTAINERS | 7 ++++ configs/tools-only_defconfig | 2 +- drivers/input/Kconfig | 9 ++++ drivers/input/Makefile | 2 + drivers/input/mouse-uclass.c | 29 +++++++++++++ include/dm/uclass-id.h | 1 + include/mouse.h | 80 ++++++++++++++++++++++++++++++++++++ 7 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 drivers/input/mouse-uclass.c create mode 100644 include/mouse.h -- 2.43.0 diff --git a/MAINTAINERS b/MAINTAINERS index 5d05281633d..e858331455c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1251,6 +1251,13 @@ S: Maintained T: git https://source.denx.de/u-boot/custodians/u-boot-i2c.git F: drivers/i2c/ +INPUT +M: Simon Glass +S: Maintained +T: git https://concept.u-boot.org/u-boot/u-boot.git +F: drivers/input +F: include/mouse.h + KWBIMAGE / KWBOOT TOOLS M: Pali Rohár M: Marek Behún diff --git a/configs/tools-only_defconfig b/configs/tools-only_defconfig index 9e4866b494c..f3c35e1a8bb 100644 --- a/configs/tools-only_defconfig +++ b/configs/tools-only_defconfig @@ -5,7 +5,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_SYS_LOAD_ADDR=0x0 CONFIG_PCI=y # CONFIG_SANDBOX_SDL is not set -# CONFIG_ULIB is not set # CONFIG_EFI_LOADER is not set CONFIG_ANDROID_BOOT_IMAGE=y CONFIG_TIMESTAMP=y @@ -30,6 +29,7 @@ CONFIG_NO_NET=y CONFIG_AXI=y CONFIG_AXI_SANDBOX=y CONFIG_SANDBOX_GPIO=y +# CONFIG_INPUT is not set CONFIG_PCI_SANDBOX=y CONFIG_DM_RTC=y CONFIG_SOUND=y diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index c2b365af11d..6bfee40ccac 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -100,3 +100,12 @@ config TWL4030_INPUT bool "Enable TWL4030 Input controller" help Enable TWL4030 Input controller + +config MOUSE + bool "Support for mice and other pointing devices" + default y if SANDBOX + help + This allows U-Boot to access mouse input, typically needed for + graphics boot menus and the like. The driver can provide mouse + events based on user interaction and these can be used to control + U-Boot's operation. diff --git a/drivers/input/Makefile b/drivers/input/Makefile index 8d4107b8848..7ed7eba3e8c 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -15,3 +15,5 @@ obj-$(CONFIG_I8042_KEYB) += i8042.o obj-$(CONFIG_TEGRA_KEYBOARD) += input.o tegra-kbc.o obj-$(CONFIG_TWL4030_INPUT) += twl4030.o endif + +obj-$(CONFIG_MOUSE) += mouse-uclass.o diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c new file mode 100644 index 00000000000..f42ef346c5c --- /dev/null +++ b/drivers/input/mouse-uclass.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include + +int mouse_get_event(struct udevice *dev, struct mouse_event *evt) +{ + struct mouse_ops *ops = mouse_get_ops(dev); + int ret; + + if (!ops->get_event) + return -ENOSYS; + + ret = ops->get_event(dev, evt); + if (ret) + return ret; + + return 0; +} + +UCLASS_DRIVER(mouse) = { + .id = UCLASS_MOUSE, + .name = "mouse", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index c558c95f465..a424ef00fc9 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -97,6 +97,7 @@ enum uclass_id { UCLASS_MISC, /* Miscellaneous device */ UCLASS_MMC, /* SD / MMC card or chip */ UCLASS_MOD_EXP, /* RSA Mod Exp device */ + UCLASS_MOUSE, /* Mouse, trackpad or other pointing device */ UCLASS_MTD, /* Memory Technology Device (MTD) device */ UCLASS_MUX, /* Multiplexer device */ UCLASS_NOP, /* No-op devices */ diff --git a/include/mouse.h b/include/mouse.h new file mode 100644 index 00000000000..c96c63918ea --- /dev/null +++ b/include/mouse.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Mouse/trackpad/touchscreen input uclass + * + * Copyright 2020 Google LLC + */ + +#ifndef _MOUSE_H +#define _MOUSE_H + +struct udevice; + +enum mouse_ev_t { + MOUSE_EV_NULL, + MOUSE_EV_MOTION, + MOUSE_EV_BUTTON, +}; + +enum mouse_state_t { + BUTTON_LEFT = 1 << 0, + BUTTON_MIDDLE = 1 << 1, + BUTTON_RIGHT = 1 << 2, + BUTTON_SCROLL_PLUS = 1 << 3, + BUTTON_SCROLL_MINUS = 1 << 4, +}; + +enum mouse_press_state_t { + BUTTON_RELEASED = 0, + BUTTON_PRESSED, +}; + +/** + * struct mouse_event - information about a mouse event + * + * @type: Mouse event ype + */ +struct mouse_event { + enum mouse_ev_t type; + union { + /** + * @state: Mouse state (enum mouse_state_t bitmask) + * @x: X position of mouse + * @y: Y position of mouse + * @xrel: Relative motion in X direction + * @yrel: Relative motion in Y direction + */ + struct mouse_motion { + unsigned char state; + unsigned short x; + unsigned short y; + short xrel; + short yrel; + } motion; + + /** + * @button: Button number that was pressed/released (BUTTON_...) + * @state: BUTTON_PRESSED / BUTTON_RELEASED + * @clicks: number of clicks (normally 1; 2 = double-click) + * @x: X position of mouse + * @y: Y position of mouse + */ + struct mouse_button { + unsigned char button; + unsigned char press_state; + unsigned char clicks; + unsigned short x; + unsigned short y; + } button; + }; +}; + +struct mouse_ops { + int (*get_event)(struct udevice *dev, struct mouse_event *event); +}; + +#define mouse_get_ops(dev) ((struct mouse_ops *)(dev)->driver->ops) + +int mouse_get_event(struct udevice *dev, struct mouse_event *event); + +#endif