blob: 20248e660750604577aa50d03b10f39c1127de49 [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 Glassb9ddbf42014-02-27 13:26:19 -070011#include <asm/sdl.h>
Simon Glassf91de0b2020-02-03 07:36:13 -070012#include <asm/state.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070013#include <asm/u-boot-sandbox.h>
Simon Glass38a2ae22016-01-18 19:52:25 -070014#include <dm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070015
16DECLARE_GLOBAL_DATA_PTR;
17
18enum {
Simon Glass38a2ae22016-01-18 19:52:25 -070019 /* Default LCD size we support */
Simon Glassb9ddbf42014-02-27 13:26:19 -070020 LCD_MAX_WIDTH = 1366,
21 LCD_MAX_HEIGHT = 768,
Simon Glassb9ddbf42014-02-27 13:26:19 -070022};
23
Simon Glass38a2ae22016-01-18 19:52:25 -070024static int sandbox_sdl_probe(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070025{
Simon Glass38a2ae22016-01-18 19:52:25 -070026 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
27 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glassf91de0b2020-02-03 07:36:13 -070028 struct sandbox_state *state = state_get_current();
Simon Glass38a2ae22016-01-18 19:52:25 -070029 int ret;
Simon Glassb9ddbf42014-02-27 13:26:19 -070030
Simon Glassf91de0b2020-02-03 07:36:13 -070031 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
32 state->double_lcd);
Simon Glass38a2ae22016-01-18 19:52:25 -070033 if (ret) {
Simon Glassb9ddbf42014-02-27 13:26:19 -070034 puts("LCD init failed\n");
Simon Glass38a2ae22016-01-18 19:52:25 -070035 return ret;
36 }
37 uc_priv->xsize = plat->xres;
38 uc_priv->ysize = plat->yres;
39 uc_priv->bpix = plat->bpix;
40 uc_priv->rot = plat->rot;
Simon Glass69f617f2016-01-14 18:10:49 -070041 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
42 uc_priv->font_size = plat->font_size;
Simon Glass38a2ae22016-01-18 19:52:25 -070043
44 return 0;
Simon Glassb9ddbf42014-02-27 13:26:19 -070045}
46
Simon Glass38a2ae22016-01-18 19:52:25 -070047static int sandbox_sdl_bind(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070048{
Simon Glass38a2ae22016-01-18 19:52:25 -070049 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
50 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
Simon Glassb9ddbf42014-02-27 13:26:19 -070051 int ret = 0;
52
Simon Glassd2caf7b2020-02-03 07:36:14 -070053 plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH);
54 plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT);
55 plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16);
Simon Glass38a2ae22016-01-18 19:52:25 -070056 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
57 debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
Simon Glassb9ddbf42014-02-27 13:26:19 -070058
59 return ret;
60}
Simon Glass38a2ae22016-01-18 19:52:25 -070061
62static const struct udevice_id sandbox_sdl_ids[] = {
63 { .compatible = "sandbox,lcd-sdl" },
64 { }
65};
66
67U_BOOT_DRIVER(sdl_sandbox) = {
68 .name = "sdl_sandbox",
69 .id = UCLASS_VIDEO,
70 .of_match = sandbox_sdl_ids,
71 .bind = sandbox_sdl_bind,
72 .probe = sandbox_sdl_probe,
73 .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat),
74};