blob: 5956b59ce49dff33ce5b1dec8f0cb22fde12d22e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb9ddbf42014-02-27 13:26:19 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glassb9ddbf42014-02-27 13:26:19 -07004 */
5
6#include <common.h>
Simon Glass38a2ae22016-01-18 19:52:25 -07007#include <dm.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -07008#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass38a2ae22016-01-18 19:52:25 -070010#include <video.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070012#include <asm/sdl.h>
Simon Glassf91de0b2020-02-03 07:36:13 -070013#include <asm/state.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070014#include <asm/u-boot-sandbox.h>
Simon Glass38a2ae22016-01-18 19:52:25 -070015#include <dm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070016
17DECLARE_GLOBAL_DATA_PTR;
18
19enum {
Simon Glass38a2ae22016-01-18 19:52:25 -070020 /* Default LCD size we support */
Simon Glassb9ddbf42014-02-27 13:26:19 -070021 LCD_MAX_WIDTH = 1366,
22 LCD_MAX_HEIGHT = 768,
Simon Glassb9ddbf42014-02-27 13:26:19 -070023};
24
Simon Glass38a2ae22016-01-18 19:52:25 -070025static int sandbox_sdl_probe(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070026{
Simon Glassb75b15b2020-12-03 16:55:23 -070027 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glassfa20e932020-12-03 16:55:20 -070028 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
Simon Glass38a2ae22016-01-18 19:52:25 -070029 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glassf91de0b2020-02-03 07:36:13 -070030 struct sandbox_state *state = state_get_current();
Simon Glass38a2ae22016-01-18 19:52:25 -070031 int ret;
Simon Glassb9ddbf42014-02-27 13:26:19 -070032
Simon Glassf91de0b2020-02-03 07:36:13 -070033 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
34 state->double_lcd);
Simon Glass38a2ae22016-01-18 19:52:25 -070035 if (ret) {
Simon Glassb9ddbf42014-02-27 13:26:19 -070036 puts("LCD init failed\n");
Simon Glass38a2ae22016-01-18 19:52:25 -070037 return ret;
38 }
39 uc_priv->xsize = plat->xres;
40 uc_priv->ysize = plat->yres;
41 uc_priv->bpix = plat->bpix;
42 uc_priv->rot = plat->rot;
Simon Glass69f617f2016-01-14 18:10:49 -070043 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
44 uc_priv->font_size = plat->font_size;
Simon Glass2a0f8e32020-07-02 21:12:29 -060045 if (IS_ENABLED(CONFIG_VIDEO_COPY))
46 uc_plat->copy_base = uc_plat->base - uc_plat->size / 2;
Simon Glass38a2ae22016-01-18 19:52:25 -070047
48 return 0;
Simon Glassb9ddbf42014-02-27 13:26:19 -070049}
50
Simon Glass38a2ae22016-01-18 19:52:25 -070051static int sandbox_sdl_bind(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070052{
Simon Glassb75b15b2020-12-03 16:55:23 -070053 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glassfa20e932020-12-03 16:55:20 -070054 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
Simon Glassb9ddbf42014-02-27 13:26:19 -070055 int ret = 0;
56
Simon Glassd2caf7b2020-02-03 07:36:14 -070057 plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
58 plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
59 plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
Simon Glasse3738822020-07-02 21:12:15 -060060 plat->rot = dev_read_u32_default(dev, "rotate", 0);
Simon Glass38a2ae22016-01-18 19:52:25 -070061 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
Simon Glass2a0f8e32020-07-02 21:12:29 -060062
63 /* Allow space for two buffers, the lower one being the copy buffer */
64 log_debug("Frame buffer size %x\n", uc_plat->size);
65 if (IS_ENABLED(CONFIG_VIDEO_COPY))
66 uc_plat->size *= 2;
Simon Glassb9ddbf42014-02-27 13:26:19 -070067
68 return ret;
69}
Simon Glass38a2ae22016-01-18 19:52:25 -070070
71static const struct udevice_id sandbox_sdl_ids[] = {
72 { .compatible = "sandbox,lcd-sdl" },
73 { }
74};
75
Walter Lozano2901ac62020-06-25 01:10:04 -030076U_BOOT_DRIVER(sandbox_lcd_sdl) = {
77 .name = "sandbox_lcd_sdl",
Simon Glass38a2ae22016-01-18 19:52:25 -070078 .id = UCLASS_VIDEO,
79 .of_match = sandbox_sdl_ids,
80 .bind = sandbox_sdl_bind,
81 .probe = sandbox_sdl_probe,
Simon Glass71fa5b42020-12-03 16:55:18 -070082 .plat_auto = sizeof(struct sandbox_sdl_plat),
Simon Glass38a2ae22016-01-18 19:52:25 -070083};