1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
11 #include <asm/global_data.h>
13 #include <asm/state.h>
14 #include <asm/u-boot-sandbox.h>
15 #include <dm/device-internal.h>
18 DECLARE_GLOBAL_DATA_PTR;
21 /* Default LCD size we support */
26 static int sandbox_sdl_probe(struct udevice *dev)
28 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
29 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
30 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
31 struct sandbox_state *state = state_get_current();
34 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
37 puts("LCD init failed\n");
40 uc_priv->xsize = plat->xres;
41 uc_priv->ysize = plat->yres;
42 uc_priv->bpix = plat->bpix;
43 uc_priv->rot = plat->rot;
44 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
45 uc_priv->font_size = plat->font_size;
46 if (IS_ENABLED(CONFIG_VIDEO_COPY))
47 uc_plat->copy_base = uc_plat->base + uc_plat->size / 2;
52 static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
54 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
55 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
59 uc_plat->size = plat->xres * plat->yres * VNBYTES(plat->bpix);
62 * Set up to the maximum size we'll ever need. This is a strange case.
63 * The video memory is allocated by video_post_bind() called from
64 * board_init_r(). If a test changes the reoslution so it needs more
65 * memory later (with sandbox_sdl_set_bpp()), it is too late to make
66 * the frame buffer larger.
68 * So use a maximum size here.
70 uc_plat->size = max(uc_plat->size, 1920U * 1080 * VNBYTES(VIDEO_BPP32));
72 /* Allow space for two buffers, the lower one being the copy buffer */
73 log_debug("Frame buffer size %x\n", uc_plat->size);
76 * If a copy framebuffer is used, double the size and use the last half
77 * as the copy, with the first half as the normal frame buffer.
79 if (IS_ENABLED(CONFIG_VIDEO_COPY))
83 int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
85 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
88 if (device_active(dev))
90 sandbox_sdl_remove_display();
92 uc_plat->hide_logo = true;
95 ret = device_probe(dev);
102 static int sandbox_sdl_remove(struct udevice *dev)
105 * Removing the display it a bit annoying when running unit tests, since
106 * they remove all devices. It is nice to be able to see what the test
107 * wrote onto the display. So this comment is just here to show how to
108 * do it, if we want to make it optional one day.
110 * sandbox_sdl_remove_display();
115 static int sandbox_sdl_bind(struct udevice *dev)
117 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
118 enum video_log2_bpp l2bpp;
121 plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
122 plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
123 l2bpp = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
124 plat->rot = dev_read_u32_default(dev, "rotate", 0);
131 static const struct udevice_id sandbox_sdl_ids[] = {
132 { .compatible = "sandbox,lcd-sdl" },
136 U_BOOT_DRIVER(sandbox_lcd_sdl) = {
137 .name = "sandbox_lcd_sdl",
139 .of_match = sandbox_sdl_ids,
140 .bind = sandbox_sdl_bind,
141 .probe = sandbox_sdl_probe,
142 .remove = sandbox_sdl_remove,
143 .plat_auto = sizeof(struct sandbox_sdl_plat),