blob: 913651c565c8affe67c7ccbd22899fe220cd59ca [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 Glass38a2ae22016-01-18 19:52:25 -07009#include <video.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070010#include <asm/sdl.h>
11#include <asm/u-boot-sandbox.h>
Simon Glass38a2ae22016-01-18 19:52:25 -070012#include <dm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070013
14DECLARE_GLOBAL_DATA_PTR;
15
16enum {
Simon Glass38a2ae22016-01-18 19:52:25 -070017 /* Default LCD size we support */
Simon Glassb9ddbf42014-02-27 13:26:19 -070018 LCD_MAX_WIDTH = 1366,
19 LCD_MAX_HEIGHT = 768,
Simon Glassb9ddbf42014-02-27 13:26:19 -070020};
21
Simon Glass38a2ae22016-01-18 19:52:25 -070022static int sandbox_sdl_probe(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070023{
Simon Glass38a2ae22016-01-18 19:52:25 -070024 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
25 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
26 int ret;
Simon Glassb9ddbf42014-02-27 13:26:19 -070027
Simon Glass38a2ae22016-01-18 19:52:25 -070028 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix);
29 if (ret) {
Simon Glassb9ddbf42014-02-27 13:26:19 -070030 puts("LCD init failed\n");
Simon Glass38a2ae22016-01-18 19:52:25 -070031 return ret;
32 }
33 uc_priv->xsize = plat->xres;
34 uc_priv->ysize = plat->yres;
35 uc_priv->bpix = plat->bpix;
36 uc_priv->rot = plat->rot;
Simon Glass69f617f2016-01-14 18:10:49 -070037 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
38 uc_priv->font_size = plat->font_size;
Simon Glass38a2ae22016-01-18 19:52:25 -070039
40 return 0;
Simon Glassb9ddbf42014-02-27 13:26:19 -070041}
42
Simon Glass38a2ae22016-01-18 19:52:25 -070043static int sandbox_sdl_bind(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070044{
Simon Glass38a2ae22016-01-18 19:52:25 -070045 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
46 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
Simon Glassb9ddbf42014-02-27 13:26:19 -070047 const void *blob = gd->fdt_blob;
Simon Glassdd79d6e2017-01-17 16:52:55 -070048 int node = dev_of_offset(dev);
Simon Glassb9ddbf42014-02-27 13:26:19 -070049 int ret = 0;
50
Simon Glass38a2ae22016-01-18 19:52:25 -070051 plat->xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH);
52 plat->yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT);
53 plat->bpix = VIDEO_BPP16;
54 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
55 debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
Simon Glassb9ddbf42014-02-27 13:26:19 -070056
57 return ret;
58}
Simon Glass38a2ae22016-01-18 19:52:25 -070059
60static const struct udevice_id sandbox_sdl_ids[] = {
61 { .compatible = "sandbox,lcd-sdl" },
62 { }
63};
64
65U_BOOT_DRIVER(sdl_sandbox) = {
66 .name = "sdl_sandbox",
67 .id = UCLASS_VIDEO,
68 .of_match = sandbox_sdl_ids,
69 .bind = sandbox_sdl_bind,
70 .probe = sandbox_sdl_probe,
71 .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat),
72};