
Hi Heinrich, On Mon, 15 Sept 2025 at 05:36, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
Am 15. September 2025 12:46:45 MESZ schrieb Simon Glass <sjg@u-boot.org>:
From: Simon Glass <sjg@chromium.org>
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 <sjg@chromium.org> ---
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
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 <sjg@chromium.org> +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 <pali@kernel.org> M: Marek Behún <kabel@kernel.org> 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 <sjg@chromium.org> + */ + +#include <dm.h> +#include <errno.h> +#include <mouse.h> + +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",
Libvirt defaults to virtio-tablet. Usb-mouse did not work for me in a spice terminal. Will this class encompass tablets, too?
So long as the mouse driver can handle it, yes. For spice, would that be virtio-tablet? Regards, Simon
Best regards
Heinrich
+}; 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
-- -- Simon Glass Executive Director Email: sjg@u-boot.org Phone: +1 970 834 3498 u-boot.org