1 /* 2 * Copyright (c) 2013 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <dm.h> 9 #include <fdtdec.h> 10 #include <video.h> 11 #include <asm/sdl.h> 12 #include <asm/u-boot-sandbox.h> 13 #include <dm/test.h> 14 15 DECLARE_GLOBAL_DATA_PTR; 16 17 enum { 18 /* Default LCD size we support */ 19 LCD_MAX_WIDTH = 1366, 20 LCD_MAX_HEIGHT = 768, 21 }; 22 23 24 /* This platform data is needed in tests, so declare it here */ 25 struct sandbox_sdl_plat { 26 int xres; 27 int yres; 28 int bpix; 29 int rot; 30 }; 31 32 static int sandbox_sdl_probe(struct udevice *dev) 33 { 34 struct sandbox_sdl_plat *plat = dev_get_platdata(dev); 35 struct video_priv *uc_priv = dev_get_uclass_priv(dev); 36 int ret; 37 38 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix); 39 if (ret) { 40 puts("LCD init failed\n"); 41 return ret; 42 } 43 uc_priv->xsize = plat->xres; 44 uc_priv->ysize = plat->yres; 45 uc_priv->bpix = plat->bpix; 46 uc_priv->rot = plat->rot; 47 48 return 0; 49 } 50 51 static int sandbox_sdl_bind(struct udevice *dev) 52 { 53 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev); 54 struct sandbox_sdl_plat *plat = dev_get_platdata(dev); 55 const void *blob = gd->fdt_blob; 56 int node = dev->of_offset; 57 int ret = 0; 58 59 plat->xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH); 60 plat->yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT); 61 plat->bpix = VIDEO_BPP16; 62 uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8; 63 debug("%s: Frame buffer size %x\n", __func__, uc_plat->size); 64 65 return ret; 66 } 67 68 static const struct udevice_id sandbox_sdl_ids[] = { 69 { .compatible = "sandbox,lcd-sdl" }, 70 { } 71 }; 72 73 U_BOOT_DRIVER(sdl_sandbox) = { 74 .name = "sdl_sandbox", 75 .id = UCLASS_VIDEO, 76 .of_match = sandbox_sdl_ids, 77 .bind = sandbox_sdl_bind, 78 .probe = sandbox_sdl_probe, 79 .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat), 80 }; 81