xref: /openbmc/u-boot/drivers/video/sandbox_sdl.c (revision 3ade5bc4dc24edf5e1f13f3c43a9e8b7f8c2d853)
17d95f2a3SSimon Glass /*
27d95f2a3SSimon Glass  * Copyright (c) 2013 Google, Inc
37d95f2a3SSimon Glass  *
47d95f2a3SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
57d95f2a3SSimon Glass  */
67d95f2a3SSimon Glass 
77d95f2a3SSimon Glass #include <common.h>
8*3ade5bc4SSimon Glass #include <dm.h>
97d95f2a3SSimon Glass #include <fdtdec.h>
10*3ade5bc4SSimon Glass #include <video.h>
117d95f2a3SSimon Glass #include <asm/sdl.h>
127d95f2a3SSimon Glass #include <asm/u-boot-sandbox.h>
13*3ade5bc4SSimon Glass #include <dm/test.h>
147d95f2a3SSimon Glass 
157d95f2a3SSimon Glass DECLARE_GLOBAL_DATA_PTR;
167d95f2a3SSimon Glass 
177d95f2a3SSimon Glass enum {
18*3ade5bc4SSimon Glass 	/* Default LCD size we support */
197d95f2a3SSimon Glass 	LCD_MAX_WIDTH		= 1366,
207d95f2a3SSimon Glass 	LCD_MAX_HEIGHT		= 768,
217d95f2a3SSimon Glass };
227d95f2a3SSimon Glass 
237d95f2a3SSimon Glass 
24*3ade5bc4SSimon Glass /* This platform data is needed in tests, so declare it here */
25*3ade5bc4SSimon Glass struct sandbox_sdl_plat {
26*3ade5bc4SSimon Glass 	int xres;
27*3ade5bc4SSimon Glass 	int yres;
28*3ade5bc4SSimon Glass 	int bpix;
29*3ade5bc4SSimon Glass 	int rot;
30*3ade5bc4SSimon Glass };
317d95f2a3SSimon Glass 
32*3ade5bc4SSimon Glass static int sandbox_sdl_probe(struct udevice *dev)
337d95f2a3SSimon Glass {
34*3ade5bc4SSimon Glass 	struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
35*3ade5bc4SSimon Glass 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
36*3ade5bc4SSimon Glass 	int ret;
377d95f2a3SSimon Glass 
38*3ade5bc4SSimon Glass 	ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix);
39*3ade5bc4SSimon Glass 	if (ret) {
407d95f2a3SSimon Glass 		puts("LCD init failed\n");
41*3ade5bc4SSimon Glass 		return ret;
42*3ade5bc4SSimon Glass 	}
43*3ade5bc4SSimon Glass 	uc_priv->xsize = plat->xres;
44*3ade5bc4SSimon Glass 	uc_priv->ysize = plat->yres;
45*3ade5bc4SSimon Glass 	uc_priv->bpix = plat->bpix;
46*3ade5bc4SSimon Glass 	uc_priv->rot = plat->rot;
47*3ade5bc4SSimon Glass 
48*3ade5bc4SSimon Glass 	return 0;
497d95f2a3SSimon Glass }
507d95f2a3SSimon Glass 
51*3ade5bc4SSimon Glass static int sandbox_sdl_bind(struct udevice *dev)
527d95f2a3SSimon Glass {
53*3ade5bc4SSimon Glass 	struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
54*3ade5bc4SSimon Glass 	struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
557d95f2a3SSimon Glass 	const void *blob = gd->fdt_blob;
56*3ade5bc4SSimon Glass 	int node = dev->of_offset;
577d95f2a3SSimon Glass 	int ret = 0;
587d95f2a3SSimon Glass 
59*3ade5bc4SSimon Glass 	plat->xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH);
60*3ade5bc4SSimon Glass 	plat->yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT);
61*3ade5bc4SSimon Glass 	plat->bpix = VIDEO_BPP16;
62*3ade5bc4SSimon Glass 	uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
63*3ade5bc4SSimon Glass 	debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
647d95f2a3SSimon Glass 
657d95f2a3SSimon Glass 	return ret;
667d95f2a3SSimon Glass }
67*3ade5bc4SSimon Glass 
68*3ade5bc4SSimon Glass static const struct udevice_id sandbox_sdl_ids[] = {
69*3ade5bc4SSimon Glass 	{ .compatible = "sandbox,lcd-sdl" },
70*3ade5bc4SSimon Glass 	{ }
71*3ade5bc4SSimon Glass };
72*3ade5bc4SSimon Glass 
73*3ade5bc4SSimon Glass U_BOOT_DRIVER(sdl_sandbox) = {
74*3ade5bc4SSimon Glass 	.name	= "sdl_sandbox",
75*3ade5bc4SSimon Glass 	.id	= UCLASS_VIDEO,
76*3ade5bc4SSimon Glass 	.of_match = sandbox_sdl_ids,
77*3ade5bc4SSimon Glass 	.bind	= sandbox_sdl_bind,
78*3ade5bc4SSimon Glass 	.probe	= sandbox_sdl_probe,
79*3ade5bc4SSimon Glass 	.platdata_auto_alloc_size	= sizeof(struct sandbox_sdl_plat),
80*3ade5bc4SSimon Glass };
81