From: Simon Glass <sjg@chromium.org> Add a mouse_set_video() function to set up the video device associated with the mouse. This allows mouse drivers to scale coordinates to match the display resolution. The video device information is stored in mouse_uc_priv rather than being driver-specific, providing a common place for all mouse drivers to access display dimensions for coordinate scaling. Update expo_set_mouse_enable() to call mouse_set_video() to configure the mouse with the display device. Co-developed-by: Claude <noreply@anthropic.com> Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/expo.c | 5 +++++ drivers/input/mouse-uclass.c | 17 +++++++++++++++++ include/mouse.h | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/boot/expo.c b/boot/expo.c index 8ec301d4dcf..99b9ad4d52b 100644 --- a/boot/expo.c +++ b/boot/expo.c @@ -178,6 +178,11 @@ int expo_set_mouse_enable(struct expo *exp, bool enable) if (ret) return log_msg_ret("sme", ret); + /* Tell the mouse driver about the video device for coordinate scaling */ + ret = mouse_set_video(exp->mouse, exp->display); + if (ret) + return log_msg_ret("msv", ret); + /* Get mouse pointer image and dimensions */ exp->mouse_ptr = video_image_getptr(riscos_arrow); if (exp->mouse_ptr) { diff --git a/drivers/input/mouse-uclass.c b/drivers/input/mouse-uclass.c index efb52d3377b..4ade394d68a 100644 --- a/drivers/input/mouse-uclass.c +++ b/drivers/input/mouse-uclass.c @@ -7,6 +7,7 @@ #include <dm.h> #include <errno.h> #include <mouse.h> +#include <video.h> int mouse_get_event(struct udevice *dev, struct mouse_event *evt) { @@ -93,6 +94,22 @@ int mouse_set_ptr_visible(struct udevice *dev, bool visible) return ops->set_ptr_visible(dev, visible); } +int mouse_set_video(struct udevice *dev, struct udevice *video_dev) +{ + struct mouse_uc_priv *uc_priv = dev_get_uclass_priv(dev); + + uc_priv->video_dev = video_dev; + if (video_dev) { + uc_priv->video_width = video_get_xsize(video_dev); + uc_priv->video_height = video_get_ysize(video_dev); + } else { + uc_priv->video_width = 0; + uc_priv->video_height = 0; + } + + return 0; +} + UCLASS_DRIVER(mouse) = { .id = UCLASS_MOUSE, .name = "mouse", diff --git a/include/mouse.h b/include/mouse.h index 98f54f73d88..560c7d14587 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -38,11 +38,17 @@ enum mouse_press_state_t { * @left_button_state: Current state of left button (BUTTON_PRESSED/BUTTON_RELEASED) * @click_pos: Position where the click occurred * @last_pos: Last position received from mouse + * @video_dev: Video device for coordinate scaling + * @video_width: Width of video display + * @video_height: Height of video display */ struct mouse_uc_priv { enum mouse_press_state_t left_button_state; struct vid_pos click_pos; struct vid_pos last_pos; + struct udevice *video_dev; + int video_width; + int video_height; }; /** @@ -159,4 +165,16 @@ int mouse_get_pos(struct udevice *dev, struct vid_pos *pos); */ int mouse_set_ptr_visible(struct udevice *dev, bool visible); +/** + * mouse_set_video() - Set the video device for coordinate scaling + * + * Sets up the video device in the mouse uclass private data so mouse drivers + * can scale coordinates to match the display resolution. + * + * @dev: Mouse device + * @video_dev: Video device + * Returns: 0 if OK, -ve on error + */ +int mouse_set_video(struct udevice *dev, struct udevice *video_dev); + #endif -- 2.43.0