[Concept,2/3] mouse: Allow selecting the device to use

Message ID 20250915193538.2316642-2-sjg@u-boot.org
State New
Headers
Series [Concept,1/3] virtio: Add input-device driver |

Commit Message

Simon Glass Sept. 15, 2025, 7:35 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Enhance the mouse dump command to support selecting a specific mouse
device by number. This allows testing multiple mouse devices when
available in the system.

Add some documentation while we are here.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/mouse.c             | 16 +++++++---
 doc/usage/cmd/mouse.rst | 66 +++++++++++++++++++++++++++++++++++++++++
 doc/usage/index.rst     |  1 +
 3 files changed, 79 insertions(+), 4 deletions(-)
 create mode 100644 doc/usage/cmd/mouse.rst
  

Patch

diff --git a/cmd/mouse.c b/cmd/mouse.c
index 60210b9f868..ee19bb07aea 100644
--- a/cmd/mouse.c
+++ b/cmd/mouse.c
@@ -18,13 +18,21 @@  static int do_mouse_dump(struct cmd_tbl *cmdtp, int flag, int argc,
 	struct udevice *dev;
 	bool running;
 	int count;
+	int mouse_dev = 0;
 	int ret;
 
-	ret = uclass_first_device_err(UCLASS_MOUSE, &dev);
+	/* Parse optional device number */
+	if (argc > 1)
+		mouse_dev = dectoul(argv[1], NULL);
+
+	/* Get the specified mouse device */
+	ret = uclass_get_device(UCLASS_MOUSE, mouse_dev, &dev);
 	if (ret) {
-		printf("Mouse not found (err=%d)\n", ret);
+		printf("Mouse device %d not found (err=%d)\n", mouse_dev, ret);
 		return CMD_RET_FAILURE;
 	}
+
+	printf("Using mouse device %d: %s\n", mouse_dev, dev->name);
 	for (running = true, count = 0; running;) {
 		struct mouse_event evt;
 
@@ -63,7 +71,7 @@  static int do_mouse_dump(struct cmd_tbl *cmdtp, int flag, int argc,
 }
 
 static char mouse_help_text[] =
-	"dump - Dump input from a mouse";
+	"dump [dev] - Dump input from mouse device (default: 0)";
 
 U_BOOT_CMD_WITH_SUBCMDS(mouse, "Mouse input", mouse_help_text,
-	U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_mouse_dump));
+	U_BOOT_SUBCMD_MKENT(dump, 2, 1, do_mouse_dump));
diff --git a/doc/usage/cmd/mouse.rst b/doc/usage/cmd/mouse.rst
new file mode 100644
index 00000000000..665980111ae
--- /dev/null
+++ b/doc/usage/cmd/mouse.rst
@@ -0,0 +1,66 @@ 
+.. SPDX-License-Identifier: GPL-2.0+:
+
+.. index::
+   single: mouse (command)
+
+mouse command
+=============
+
+Synopsis
+--------
+
+::
+
+    mouse dump [dev]
+
+The mouse command is used to access mouse input devices.
+
+mouse dump
+----------
+
+Dump input events from a mouse device in real-time. Events are displayed
+until the user presses Ctrl+C to stop.
+
+dev
+    Optional device number (default: 0). Use this to select a specific mouse
+    device when multiple mouse devices are available.
+
+The command displays:
+- Motion events with absolute/relative coordinates and button state
+- Button events (left, right, middle) with press/release state and position
+- Event count when finished
+
+Example
+-------
+
+::
+
+    => mouse dump
+    Using mouse device 0: xhci_pci.p0.usb_hub.p6.usb_mo
+    motion: Xrel=-27, Yrel=84, X=0, Y=84, but=0
+    motion: Xrel=-78, Yrel=87, X=0, Y=171, but=0
+    motion: Xrel=-1, Yrel=87, X=0, Y=258, but=0
+    motion: Xrel=76, Yrel=88, X=76, Y=346, but=0
+    button: button==0, press=1, clicks=1, X=76, Y=346
+    motion: Xrel=76, Yrel=88, X=152, Y=434, but=1
+    motion: Xrel=76, Yrel=88, X=228, Y=522, but=1
+    motion: Xrel=76, Yrel=88, X=304, Y=610, but=1
+    motion: Xrel=76, Yrel=88, X=380, Y=698, but=1
+    button: button==0, press=0, clicks=1, X=380, Y=698
+    motion: Xrel=76, Yrel=88, X=456, Y=786, but=0
+    motion: Xrel=76, Yrel=88, X=532, Y=874, but=0
+    motion: Xrel=50, Yrel=88, X=582, Y=962, but=0
+    motion: Xrel=-1, Yrel=87, X=581, Y=1049, but=0
+    motion: Xrel=76, Yrel=87, X=657, Y=1136, but=0
+    motion: Xrel=-104, Yrel=86, X=553, Y=1222, but=0
+    motion: Xrel=24, Yrel=86, X=577, Y=1308, but=0
+    motion: Xrel=-104, Yrel=85, X=473, Y=1393, but=0
+    18 events received
+
+    => mouse dump 1
+    Mouse device 1 not found (err=-19)
+
+Configuration
+-------------
+
+The mouse command is available when CONFIG_CMD_MOUSE is enabled.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index eeda632b1a0..c03ea7df7c4 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -94,6 +94,7 @@  Shell commands
    cmd/mbr
    cmd/md
    cmd/mmc
+   cmd/mouse
    cmd/msr
    cmd/mtest
    cmd/mtrr