blob: 21448a14115bd65dfab8c3985b94abcf736c2129 [file] [log] [blame]
Simon Glassb9ddbf42014-02-27 13:26:19 -07001/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Simon Glass38a2ae22016-01-18 19:52:25 -07008#include <dm.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -07009#include <fdtdec.h>
Simon Glass38a2ae22016-01-18 19:52:25 -070010#include <video.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070011#include <asm/sdl.h>
12#include <asm/u-boot-sandbox.h>
Simon Glass38a2ae22016-01-18 19:52:25 -070013#include <dm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070014
15DECLARE_GLOBAL_DATA_PTR;
16
17enum {
Simon Glass38a2ae22016-01-18 19:52:25 -070018 /* Default LCD size we support */
Simon Glassb9ddbf42014-02-27 13:26:19 -070019 LCD_MAX_WIDTH = 1366,
20 LCD_MAX_HEIGHT = 768,
Simon Glassb9ddbf42014-02-27 13:26:19 -070021};
22
Simon Glass38a2ae22016-01-18 19:52:25 -070023static int sandbox_sdl_probe(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070024{
Simon Glass38a2ae22016-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);
27 int ret;
Simon Glassb9ddbf42014-02-27 13:26:19 -070028
Simon Glass38a2ae22016-01-18 19:52:25 -070029 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix);
30 if (ret) {
Simon Glassb9ddbf42014-02-27 13:26:19 -070031 puts("LCD init failed\n");
Simon Glass38a2ae22016-01-18 19:52:25 -070032 return ret;
33 }
34 uc_priv->xsize = plat->xres;
35 uc_priv->ysize = plat->yres;
36 uc_priv->bpix = plat->bpix;
37 uc_priv->rot = plat->rot;
38
39 return 0;
Simon Glassb9ddbf42014-02-27 13:26:19 -070040}
41
Simon Glass38a2ae22016-01-18 19:52:25 -070042static int sandbox_sdl_bind(struct udevice *dev)
Simon Glassb9ddbf42014-02-27 13:26:19 -070043{
Simon Glass38a2ae22016-01-18 19:52:25 -070044 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
45 struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
Simon Glassb9ddbf42014-02-27 13:26:19 -070046 const void *blob = gd->fdt_blob;
Simon Glass38a2ae22016-01-18 19:52:25 -070047 int node = dev->of_offset;
Simon Glassb9ddbf42014-02-27 13:26:19 -070048 int ret = 0;
49
Simon Glass38a2ae22016-01-18 19:52:25 -070050 plat->xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH);
51 plat->yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT);
52 plat->bpix = VIDEO_BPP16;
53 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
54 debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
Simon Glassb9ddbf42014-02-27 13:26:19 -070055
56 return ret;
57}
Simon Glass38a2ae22016-01-18 19:52:25 -070058
59static const struct udevice_id sandbox_sdl_ids[] = {
60 { .compatible = "sandbox,lcd-sdl" },
61 { }
62};
63
64U_BOOT_DRIVER(sdl_sandbox) = {
65 .name = "sdl_sandbox",
66 .id = UCLASS_VIDEO,
67 .of_match = sandbox_sdl_ids,
68 .bind = sandbox_sdl_bind,
69 .probe = sandbox_sdl_probe,
70 .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat),
71};