From patchwork Mon Aug 25 20:40:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 139 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=1756154438; bh=Z0OHH0aDIJaB3o91yfJtyaznWynjWu1pgtdDjRI9Odc=; 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=SnFx5kCS3JEpWPdjfTtZWjGbBOElMYjkNHr0z95e7MX40o4YhptX9fluvcBWdPdXI oVeZY+1SCc+KXdxkftXufUb3o+i035c2zHqNqzJVfSB+4eyoozkGUb+4ay0AsQPPeo AlT2tFbfMAgm4oOIbDZJeXFkhNfM1RlTFF9IWqR83T4ZdIFALyaebkwYyVzTIhi10y 7DcPqGwSNmJJKpbkwKhw3pOKE0MzpJdW3tW3dIR1ImPLMzwDG5hoHs06/7s2npI8Lq 3ZcHA0nL5L93gNnjkR2TLVMl8vhlC+3TLs50nUHtzZPcn7UzA+lT6yXnHOu3JjtXKV mAfSL2/zQd9cA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 46FAD67787 for ; Mon, 25 Aug 2025 14:40:38 -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 yfXVIVE4_PX5 for ; Mon, 25 Aug 2025 14:40:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756154437; bh=Z0OHH0aDIJaB3o91yfJtyaznWynjWu1pgtdDjRI9Odc=; 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=ZOTEnqpvY4f/WKZIzpzsH4L8iDIYKbHg4CR9uScxC1QgKcxJle7Wr4h1j9Yyuaop0 q264VpcK9l3N4fGYBip5NkDD69ASXZlelY7dBjGACG2AUYcCWu1Aq7TQpcj0DtHqbe BbhDbHbMilhPyW6QYa7LZOTTl1ikTdHhKqV17rOL7wjEX3GAUW/itJW974pi4Tsoiv hhB+iUZOaST52nIAa7hTdO5ZopHtHqnXlFEgZqXf40R4oMBx93AS15ZkuBhqMqrLrq yT6TEZtEUXYtjJzt8B4vrLKKRp5FZSnhsdUo/k8hcD0bVpTW3riR4sp391e/XHM5XX iz0AG/W782/fA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 543276778C for ; Mon, 25 Aug 2025 14:40:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756154434; bh=GIkUNmy8fnjEDFSZwu5JJNFjyHFbOm9rBJ4gFeJe+QI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hioH9RkK+Zes5JOlLw0FKzeExtHfG3xJOoDpw1Oxp0OaSs3329CJEmz5Gjd6D8DpN /+29yTHBJ9N6GGwBPXFQ2sQRs7eqq+rnQBbgjOVxactI3Ne48aFlNt1tBjvP64pgpP /bssq7XiZBSo3dcm6I0kaV9hfbkAQFZDB8D8lI9m6o6qSWIkuKf4jAmM4GAGMx9N4z x/nnl9gQ16ix6yUJxngF8nWNFp7OS0rqmjZVvhI+GKagXARMvR54OuwK2ZGCGzpm4e RTWeF3HU5PQBYF2qScn62Msn+ilVhaY3QvxneRb8csw/Qzc8OQsi30hWnCDaZIhwR1 bZrVRk2SEwfLA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AE4AF6778C; Mon, 25 Aug 2025 14:40:34 -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 FYvsF9z1uDgo; Mon, 25 Aug 2025 14:40:34 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1756154434; bh=45WMtjCNaIYP2pNmovsU8gSeSBPXmr+88tZuiQtNoPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=btjr+2Q5T1r1LMuJeu8Bdmis4yMMZnDrOh3mdOEEf16W75x+zv8/o0UiZVS3r1h/r mhdxHF1nhuvWlnCj4HKEMHFMM2Jwf97UpVWT2v2jn1VdwFNMqQAgibfN/bW5aM8r01 DT2DbAwtMsRdymDvudNXFwXCsJZCu41w74yWZ625dMMqtsz56LmE0+4EfvrYuIPaJ6 SHcjQGU9WtwTvMhqoUT9xBNYtydllJ4uxdkeje5mcJq99O5VM+HJkb8XLaCjC+EV1C xEeM5yALS4uytvVa4B3TIn7Hp6VWJ1Pz3yxYOU0EuiCrSRZUNzAWj2V8ij1HFlUfPS DQFmpn7zvNSkA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 17C4867709; Mon, 25 Aug 2025 14:40:34 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 25 Aug 2025 14:40:15 -0600 Message-ID: <20250825204022.3655799-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250825204022.3655799-1-sjg@u-boot.org> References: <20250825204022.3655799-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MKKE4GFPL2VWAPPQF33CYT5LBH2WWPUQ X-Message-ID-Hash: MKKE4GFPL2VWAPPQF33CYT5LBH2WWPUQ 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 2/6] 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. Signed-off-by: Simon Glass --- drivers/input/Kconfig | 9 ++++ drivers/input/Makefile | 3 ++ drivers/input/mouse-uclass.c | 28 +++++++++++++ drivers/input/sandbox_mouse.c | 35 ++++++++++++++++ include/dm/uclass-id.h | 1 + include/mouse.h | 78 +++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 drivers/input/mouse-uclass.c create mode 100644 drivers/input/sandbox_mouse.c create mode 100644 include/mouse.h 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..a4938d19903 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -15,3 +15,6 @@ 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 +obj-$(CONFIG_SANDBOX) += sandbox_mouse.o diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c new file mode 100644 index 00000000000..ddf948f7e78 --- /dev/null +++ b/drivers/input/mouse-uclass.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019 Google LLC + * Written by Simon Glass + */ + +#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/drivers/input/sandbox_mouse.c b/drivers/input/sandbox_mouse.c new file mode 100644 index 00000000000..4aedf0fdf2d --- /dev/null +++ b/drivers/input/sandbox_mouse.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include + +static int mouse_sandbox_get_event(struct udevice *dev, + struct mouse_event *event) +{ + int ret; + + ret = sandbox_sdl_get_mouse_event(event); + + return ret; +} + +const struct mouse_ops mouse_sandbox_ops = { + .get_event = mouse_sandbox_get_event, +}; + +static const struct udevice_id mouse_sandbox_ids[] = { + { .compatible = "sandbox,mouse" }, + { } +}; + +U_BOOT_DRIVER(mouse_sandbox) = { + .name = "mouse_sandbox", + .id = UCLASS_MOUSE, + .of_match = mouse_sandbox_ids, + .ops = &mouse_sandbox_ops, +}; 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..81704047f5d --- /dev/null +++ b/include/mouse.h @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Mouse/trackpad/touchscreen input uclass + * + * Copyright 2020 Google LLC + */ + +#ifndef _MOUSE_H +#define _MOUSE_H + +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