Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 8 | #include <fdtdec.h> |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 9 | #include <video.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 10 | #include <asm/sdl.h> |
| 11 | #include <asm/u-boot-sandbox.h> |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 12 | #include <dm/test.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
| 16 | enum { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 17 | /* Default LCD size we support */ |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 18 | LCD_MAX_WIDTH = 1366, |
| 19 | LCD_MAX_HEIGHT = 768, |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 22 | static int sandbox_sdl_probe(struct udevice *dev) |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 23 | { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 24 | struct sandbox_sdl_plat *plat = dev_get_platdata(dev); |
| 25 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
| 26 | int ret; |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 27 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 28 | ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix); |
| 29 | if (ret) { |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 30 | puts("LCD init failed\n"); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 31 | 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 Glass | 69f617f | 2016-01-14 18:10:49 -0700 | [diff] [blame] | 37 | uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name; |
| 38 | uc_priv->font_size = plat->font_size; |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 39 | |
| 40 | return 0; |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 43 | static int sandbox_sdl_bind(struct udevice *dev) |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 44 | { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 45 | struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev); |
| 46 | struct sandbox_sdl_plat *plat = dev_get_platdata(dev); |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 47 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 48 | int node = dev_of_offset(dev); |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 49 | int ret = 0; |
| 50 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 51 | 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 Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 56 | |
| 57 | return ret; |
| 58 | } |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 59 | |
| 60 | static const struct udevice_id sandbox_sdl_ids[] = { |
| 61 | { .compatible = "sandbox,lcd-sdl" }, |
| 62 | { } |
| 63 | }; |
| 64 | |
| 65 | U_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 | }; |