2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-02-27 20:26:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-01-19 02:52:25 +00:00
|
|
|
#include <dm.h>
|
2014-02-27 20:26:19 +00:00
|
|
|
#include <fdtdec.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2016-01-19 02:52:25 +00:00
|
|
|
#include <video.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2014-02-27 20:26:19 +00:00
|
|
|
#include <asm/sdl.h>
|
2020-02-03 14:36:13 +00:00
|
|
|
#include <asm/state.h>
|
2014-02-27 20:26:19 +00:00
|
|
|
#include <asm/u-boot-sandbox.h>
|
2021-11-19 20:23:50 +00:00
|
|
|
#include <dm/device-internal.h>
|
2016-01-19 02:52:25 +00:00
|
|
|
#include <dm/test.h>
|
2014-02-27 20:26:19 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
enum {
|
2016-01-19 02:52:25 +00:00
|
|
|
/* Default LCD size we support */
|
2014-02-27 20:26:19 +00:00
|
|
|
LCD_MAX_WIDTH = 1366,
|
|
|
|
LCD_MAX_HEIGHT = 768,
|
|
|
|
};
|
|
|
|
|
2016-01-19 02:52:25 +00:00
|
|
|
static int sandbox_sdl_probe(struct udevice *dev)
|
2014-02-27 20:26:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct sandbox_sdl_plat *plat = dev_get_plat(dev);
|
2016-01-19 02:52:25 +00:00
|
|
|
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
|
2020-02-03 14:36:13 +00:00
|
|
|
struct sandbox_state *state = state_get_current();
|
2016-01-19 02:52:25 +00:00
|
|
|
int ret;
|
2014-02-27 20:26:19 +00:00
|
|
|
|
2020-02-03 14:36:13 +00:00
|
|
|
ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
|
|
|
|
state->double_lcd);
|
2016-01-19 02:52:25 +00:00
|
|
|
if (ret) {
|
2014-02-27 20:26:19 +00:00
|
|
|
puts("LCD init failed\n");
|
2016-01-19 02:52:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
uc_priv->xsize = plat->xres;
|
|
|
|
uc_priv->ysize = plat->yres;
|
|
|
|
uc_priv->bpix = plat->bpix;
|
|
|
|
uc_priv->rot = plat->rot;
|
2016-01-15 01:10:49 +00:00
|
|
|
uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
|
|
|
|
uc_priv->font_size = plat->font_size;
|
2020-07-03 03:12:29 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_COPY))
|
2021-11-19 20:23:49 +00:00
|
|
|
uc_plat->copy_base = uc_plat->base + uc_plat->size / 2;
|
2016-01-19 02:52:25 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-02-27 20:26:19 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 20:23:45 +00:00
|
|
|
static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
|
2014-02-27 20:26:19 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct sandbox_sdl_plat *plat = dev_get_plat(dev);
|
2014-02-27 20:26:19 +00:00
|
|
|
|
2021-11-19 20:23:45 +00:00
|
|
|
plat->bpix = l2bpp;
|
|
|
|
|
2021-11-19 20:23:48 +00:00
|
|
|
uc_plat->size = plat->xres * plat->yres * VNBYTES(plat->bpix);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up to the maximum size we'll ever need. This is a strange case.
|
|
|
|
* The video memory is allocated by video_post_bind() called from
|
|
|
|
* board_init_r(). If a test changes the reoslution so it needs more
|
|
|
|
* memory later (with sandbox_sdl_set_bpp()), it is too late to make
|
|
|
|
* the frame buffer larger.
|
|
|
|
*
|
|
|
|
* So use a maximum size here.
|
|
|
|
*/
|
|
|
|
uc_plat->size = max(uc_plat->size, 1920U * 1080 * VNBYTES(VIDEO_BPP32));
|
2020-07-03 03:12:29 +00:00
|
|
|
|
|
|
|
/* Allow space for two buffers, the lower one being the copy buffer */
|
|
|
|
log_debug("Frame buffer size %x\n", uc_plat->size);
|
2021-11-19 20:23:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a copy framebuffer is used, double the size and use the last half
|
|
|
|
* as the copy, with the first half as the normal frame buffer.
|
|
|
|
*/
|
2020-07-03 03:12:29 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_COPY))
|
|
|
|
uc_plat->size *= 2;
|
2021-11-19 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 20:23:50 +00:00
|
|
|
int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
|
|
|
|
{
|
2021-11-19 20:24:03 +00:00
|
|
|
struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
|
2021-11-19 20:23:50 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (device_active(dev))
|
|
|
|
return -EINVAL;
|
|
|
|
sandbox_sdl_remove_display();
|
|
|
|
|
2021-11-19 20:24:03 +00:00
|
|
|
uc_plat->hide_logo = true;
|
2021-11-19 20:23:50 +00:00
|
|
|
set_bpp(dev, l2bpp);
|
|
|
|
|
|
|
|
ret = device_probe(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-19 20:23:46 +00:00
|
|
|
static int sandbox_sdl_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Removing the display it a bit annoying when running unit tests, since
|
|
|
|
* they remove all devices. It is nice to be able to see what the test
|
|
|
|
* wrote onto the display. So this comment is just here to show how to
|
|
|
|
* do it, if we want to make it optional one day.
|
|
|
|
*
|
|
|
|
* sandbox_sdl_remove_display();
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-19 20:23:45 +00:00
|
|
|
static int sandbox_sdl_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sandbox_sdl_plat *plat = dev_get_plat(dev);
|
|
|
|
enum video_log2_bpp l2bpp;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
|
|
|
|
plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
|
|
|
|
l2bpp = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
|
|
|
|
plat->rot = dev_read_u32_default(dev, "rotate", 0);
|
|
|
|
|
|
|
|
set_bpp(dev, l2bpp);
|
2014-02-27 20:26:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-19 02:52:25 +00:00
|
|
|
|
|
|
|
static const struct udevice_id sandbox_sdl_ids[] = {
|
|
|
|
{ .compatible = "sandbox,lcd-sdl" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
U_BOOT_DRIVER(sandbox_lcd_sdl) = {
|
|
|
|
.name = "sandbox_lcd_sdl",
|
2016-01-19 02:52:25 +00:00
|
|
|
.id = UCLASS_VIDEO,
|
|
|
|
.of_match = sandbox_sdl_ids,
|
|
|
|
.bind = sandbox_sdl_bind,
|
|
|
|
.probe = sandbox_sdl_probe,
|
2021-11-19 20:23:46 +00:00
|
|
|
.remove = sandbox_sdl_remove,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct sandbox_sdl_plat),
|
2016-01-19 02:52:25 +00:00
|
|
|
};
|