xref: /openbmc/u-boot/drivers/video/sandbox_sdl.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
27d95f2a3SSimon Glass /*
37d95f2a3SSimon Glass  * Copyright (c) 2013 Google, Inc
47d95f2a3SSimon Glass  */
57d95f2a3SSimon Glass 
67d95f2a3SSimon Glass #include <common.h>
73ade5bc4SSimon Glass #include <dm.h>
87d95f2a3SSimon Glass #include <fdtdec.h>
93ade5bc4SSimon Glass #include <video.h>
107d95f2a3SSimon Glass #include <asm/sdl.h>
117d95f2a3SSimon Glass #include <asm/u-boot-sandbox.h>
123ade5bc4SSimon Glass #include <dm/test.h>
137d95f2a3SSimon Glass 
147d95f2a3SSimon Glass DECLARE_GLOBAL_DATA_PTR;
157d95f2a3SSimon Glass 
167d95f2a3SSimon Glass enum {
173ade5bc4SSimon Glass 	/* Default LCD size we support */
187d95f2a3SSimon Glass 	LCD_MAX_WIDTH		= 1366,
197d95f2a3SSimon Glass 	LCD_MAX_HEIGHT		= 768,
207d95f2a3SSimon Glass };
217d95f2a3SSimon Glass 
sandbox_sdl_probe(struct udevice * dev)223ade5bc4SSimon Glass static int sandbox_sdl_probe(struct udevice *dev)
237d95f2a3SSimon Glass {
243ade5bc4SSimon Glass 	struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
253ade5bc4SSimon Glass 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
263ade5bc4SSimon Glass 	int ret;
277d95f2a3SSimon Glass 
283ade5bc4SSimon Glass 	ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix);
293ade5bc4SSimon Glass 	if (ret) {
307d95f2a3SSimon Glass 		puts("LCD init failed\n");
313ade5bc4SSimon Glass 		return ret;
323ade5bc4SSimon Glass 	}
333ade5bc4SSimon Glass 	uc_priv->xsize = plat->xres;
343ade5bc4SSimon Glass 	uc_priv->ysize = plat->yres;
353ade5bc4SSimon Glass 	uc_priv->bpix = plat->bpix;
363ade5bc4SSimon Glass 	uc_priv->rot = plat->rot;
378de536c2SSimon Glass 	uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
388de536c2SSimon Glass 	uc_priv->font_size = plat->font_size;
393ade5bc4SSimon Glass 
403ade5bc4SSimon Glass 	return 0;
417d95f2a3SSimon Glass }
427d95f2a3SSimon Glass 
sandbox_sdl_bind(struct udevice * dev)433ade5bc4SSimon Glass static int sandbox_sdl_bind(struct udevice *dev)
447d95f2a3SSimon Glass {
453ade5bc4SSimon Glass 	struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
463ade5bc4SSimon Glass 	struct sandbox_sdl_plat *plat = dev_get_platdata(dev);
477d95f2a3SSimon Glass 	const void *blob = gd->fdt_blob;
48e160f7d4SSimon Glass 	int node = dev_of_offset(dev);
497d95f2a3SSimon Glass 	int ret = 0;
507d95f2a3SSimon Glass 
513ade5bc4SSimon Glass 	plat->xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH);
523ade5bc4SSimon Glass 	plat->yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT);
533ade5bc4SSimon Glass 	plat->bpix = VIDEO_BPP16;
543ade5bc4SSimon Glass 	uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8;
553ade5bc4SSimon Glass 	debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
567d95f2a3SSimon Glass 
577d95f2a3SSimon Glass 	return ret;
587d95f2a3SSimon Glass }
593ade5bc4SSimon Glass 
603ade5bc4SSimon Glass static const struct udevice_id sandbox_sdl_ids[] = {
613ade5bc4SSimon Glass 	{ .compatible = "sandbox,lcd-sdl" },
623ade5bc4SSimon Glass 	{ }
633ade5bc4SSimon Glass };
643ade5bc4SSimon Glass 
653ade5bc4SSimon Glass U_BOOT_DRIVER(sdl_sandbox) = {
663ade5bc4SSimon Glass 	.name	= "sdl_sandbox",
673ade5bc4SSimon Glass 	.id	= UCLASS_VIDEO,
683ade5bc4SSimon Glass 	.of_match = sandbox_sdl_ids,
693ade5bc4SSimon Glass 	.bind	= sandbox_sdl_bind,
703ade5bc4SSimon Glass 	.probe	= sandbox_sdl_probe,
713ade5bc4SSimon Glass 	.platdata_auto_alloc_size	= sizeof(struct sandbox_sdl_plat),
723ade5bc4SSimon Glass };
73