blob: 12edf9c90c986cffcf6200cb220f74d7b3f9cc2d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass7d95f2a2014-02-27 13:26:19 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glass7d95f2a2014-02-27 13:26:19 -07004 */
5
6#include <common.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -07007#include <dm.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -07008#include <fdtdec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -070010#include <video.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070011#include <asm/sdl.h>
Simon Glass6be88c72020-02-03 07:36:13 -070012#include <asm/state.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070013#include <asm/u-boot-sandbox.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -070014#include <dm/test.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070015
16DECLARE_GLOBAL_DATA_PTR;
17
18enum {
Simon Glass3ade5bc2016-01-18 19:52:25 -070019 /* Default LCD size we support */
Simon Glass7d95f2a2014-02-27 13:26:19 -070020 LCD_MAX_WIDTH = 1366,
21 LCD_MAX_HEIGHT = 768,
Simon Glass7d95f2a2014-02-27 13:26:19 -070022};
23
Simon Glass3ade5bc2016-01-18 19:52:25 -070024static int sandbox_sdl_probe(struct udevice *dev)
Simon Glass7d95f2a2014-02-27 13:26:19 -070025{
Simon Glass8a8d24b2020-12-03 16:55:23 -070026 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glassc69cda22020-12-03 16:55:20 -070027 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
Simon Glass3ade5bc2016-01-18 19:52:25 -070028 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass6be88c72020-02-03 07:36:13 -070029 struct sandbox_state *state = state_get_current();
Simon Glass3ade5bc2016-01-18 19:52:25 -070030 int ret;
Simon Glass7d95f2a2014-02-27 13:26:19 -070031
Simon Glass6be88c72020-02-03 07:36:13 -070032 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
33 state->double_lcd);
Simon Glass3ade5bc2016-01-18 19:52:25 -070034 if (ret) {
Simon Glass7d95f2a2014-02-27 13:26:19 -070035 puts("LCD init failed\n");
Simon Glass3ade5bc2016-01-18 19:52:25 -070036 return ret;
37 }
38 uc_priv->xsize = plat->xres;
39 uc_priv->ysize = plat->yres;
40 uc_priv->bpix = plat->bpix;
41 uc_priv->rot = plat->rot;
Simon Glass8de536c2016-01-14 18:10:49 -070042 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
43 uc_priv->font_size = plat->font_size;
Simon Glassf578ca72020-07-02 21:12:29 -060044 if (IS_ENABLED(CONFIG_VIDEO_COPY))
45 uc_plat->copy_base = uc_plat->base - uc_plat->size / 2;
Simon Glass3ade5bc2016-01-18 19:52:25 -070046
47 return 0;
Simon Glass7d95f2a2014-02-27 13:26:19 -070048}
49
Simon Glass3ade5bc2016-01-18 19:52:25 -070050static int sandbox_sdl_bind(struct udevice *dev)
Simon Glass7d95f2a2014-02-27 13:26:19 -070051{
Simon Glass8a8d24b2020-12-03 16:55:23 -070052 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glassc69cda22020-12-03 16:55:20 -070053 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
Simon Glass7d95f2a2014-02-27 13:26:19 -070054 int ret = 0;
55
Simon Glassa466db52020-02-03 07:36:14 -070056 plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
57 plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
58 plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
Simon Glass6a2ea432020-07-02 21:12:15 -060059 plat->rot = dev_read_u32_default(dev, "rotate", 0);
Simon Glass3ade5bc2016-01-18 19:52:25 -070060 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
Simon Glassf578ca72020-07-02 21:12:29 -060061
62 /* Allow space for two buffers, the lower one being the copy buffer */
63 log_debug("Frame buffer size %x\n", uc_plat->size);
64 if (IS_ENABLED(CONFIG_VIDEO_COPY))
65 uc_plat->size *= 2;
Simon Glass7d95f2a2014-02-27 13:26:19 -070066
67 return ret;
68}
Simon Glass3ade5bc2016-01-18 19:52:25 -070069
70static const struct udevice_id sandbox_sdl_ids[] = {
71 { .compatible = "sandbox,lcd-sdl" },
72 { }
73};
74
Walter Lozanoe3e24702020-06-25 01:10:04 -030075U_BOOT_DRIVER(sandbox_lcd_sdl) = {
76 .name = "sandbox_lcd_sdl",
Simon Glass3ade5bc2016-01-18 19:52:25 -070077 .id = UCLASS_VIDEO,
78 .of_match = sandbox_sdl_ids,
79 .bind = sandbox_sdl_bind,
80 .probe = sandbox_sdl_probe,
Simon Glasscaa4daa2020-12-03 16:55:18 -070081 .plat_auto = sizeof(struct sandbox_sdl_plat),
Simon Glass3ade5bc2016-01-18 19:52:25 -070082};