[Concept,06/17] input: sandbox: Provide a mouse driver

Message ID 20250915104705.937780-7-sjg@u-boot.org
State New
Headers
Series mouse: Provide some support for using a mouse |

Commit Message

Simon Glass Sept. 15, 2025, 10:46 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add a sandbox driver for the mouse, so it can be used as an input
device.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/input/Kconfig         |  1 +
 drivers/input/Makefile        |  3 +++
 drivers/input/sandbox_mouse.c | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+)
 create mode 100644 drivers/input/sandbox_mouse.c
  

Patch

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 6bfee40ccac..101257f9767 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -103,6 +103,7 @@  config TWL4030_INPUT
 
 config MOUSE
 	bool "Support for mice and other pointing devices"
+	depends on INPUT
 	default y if SANDBOX
 	help
 	  This allows U-Boot to access mouse input, typically needed for
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 7ed7eba3e8c..8c5a395a540 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -17,3 +17,6 @@  obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
 endif
 
 obj-$(CONFIG_MOUSE) += mouse-uclass.o
+ifdef CONFIG_MOUSE
+obj-$(CONFIG_SANDBOX) += sandbox_mouse.o
+endif
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 <sjg@chromium.org>
+ */
+
+#include <dm.h>
+#include <mouse.h>
+#include <asm/sdl.h>
+
+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,
+};