blob: 1196e6c671771d849b35b041da71a4ea574412af [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 Glass3ade5bc2016-01-18 19:52:25 -07009#include <video.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070010#include <asm/sdl.h>
Simon Glass6be88c72020-02-03 07:36:13 -070011#include <asm/state.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070012#include <asm/u-boot-sandbox.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -070013#include <dm/test.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070014
15DECLARE_GLOBAL_DATA_PTR;
16
17enum {
Simon Glass3ade5bc2016-01-18 19:52:25 -070018 /* Default LCD size we support */
Simon Glass7d95f2a2014-02-27 13:26:19 -070019 LCD_MAX_WIDTH = 1366,
20 LCD_MAX_HEIGHT = 768,
Simon Glass7d95f2a2014-02-27 13:26:19 -070021};
22
Simon Glass3ade5bc2016-01-18 19:52:25 -070023static int sandbox_sdl_probe(struct udevice *dev)
Simon Glass7d95f2a2014-02-27 13:26:19 -070024{
Simon Glass3ade5bc2016-01-18 19:52:25 -070025 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
26 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass6be88c72020-02-03 07:36:13 -070027 struct sandbox_state *state = state_get_current();
Simon Glass3ade5bc2016-01-18 19:52:25 -070028 int ret;
Simon Glass7d95f2a2014-02-27 13:26:19 -070029
Simon Glass6be88c72020-02-03 07:36:13 -070030 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
31 state->double_lcd);
Simon Glass3ade5bc2016-01-18 19:52:25 -070032 if (ret) {
Simon Glass7d95f2a2014-02-27 13:26:19 -070033 puts("LCD init failed\n");
Simon Glass3ade5bc2016-01-18 19:52:25 -070034 return ret;
35 }
36 uc_priv->xsize = plat->xres;
37 uc_priv->ysize = plat->yres;
38 uc_priv->bpix = plat->bpix;
39 uc_priv->rot = plat->rot;
Simon Glass8de536c2016-01-14 18:10:49 -070040 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
41 uc_priv->font_size = plat->font_size;
Simon Glass3ade5bc2016-01-18 19:52:25 -070042
43 return 0;
Simon Glass7d95f2a2014-02-27 13:26:19 -070044}
45
Simon Glass3ade5bc2016-01-18 19:52:25 -070046static int sandbox_sdl_bind(struct udevice *dev)
Simon Glass7d95f2a2014-02-27 13:26:19 -070047{
Simon Glass3ade5bc2016-01-18 19:52:25 -070048 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
49 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
Simon Glass7d95f2a2014-02-27 13:26:19 -070050 int ret = 0;
51
Simon Glassa466db52020-02-03 07:36:14 -070052 plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
53 plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
54 plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
Simon Glass3ade5bc2016-01-18 19:52:25 -070055 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
56 debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
Simon Glass7d95f2a2014-02-27 13:26:19 -070057
58 return ret;
59}
Simon Glass3ade5bc2016-01-18 19:52:25 -070060
61static const struct udevice_id sandbox_sdl_ids[] = {
62 { .compatible = "sandbox,lcd-sdl" },
63 { }
64};
65
66U_BOOT_DRIVER(sdl_sandbox) = {
67 .name = "sdl_sandbox",
68 .id = UCLASS_VIDEO,
69 .of_match = sandbox_sdl_ids,
70 .bind = sandbox_sdl_bind,
71 .probe = sandbox_sdl_probe,
72 .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat),
73};