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 | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 10 | #include <video.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 11 | #include <asm/sdl.h> |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 12 | #include <asm/state.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 13 | #include <asm/u-boot-sandbox.h> |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 14 | #include <dm/test.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | enum { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 19 | /* Default LCD size we support */ |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 20 | LCD_MAX_WIDTH = 1366, |
| 21 | LCD_MAX_HEIGHT = 768, |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 24 | static int sandbox_sdl_probe(struct udevice *dev) |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 25 | { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 26 | struct sandbox_sdl_plat *plat = dev_get_platdata(dev); |
| 27 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 28 | struct sandbox_state *state = state_get_current(); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 29 | int ret; |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 30 | |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 31 | ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix, |
| 32 | state->double_lcd); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 33 | if (ret) { |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 34 | puts("LCD init failed\n"); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 35 | return ret; |
| 36 | } |
| 37 | uc_priv->xsize = plat->xres; |
| 38 | uc_priv->ysize = plat->yres; |
| 39 | uc_priv->bpix = plat->bpix; |
| 40 | uc_priv->rot = plat->rot; |
Simon Glass | 69f617f | 2016-01-14 18:10:49 -0700 | [diff] [blame] | 41 | uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name; |
| 42 | uc_priv->font_size = plat->font_size; |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 43 | |
| 44 | return 0; |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 47 | static int sandbox_sdl_bind(struct udevice *dev) |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 48 | { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 49 | struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev); |
| 50 | struct sandbox_sdl_plat *plat = dev_get_platdata(dev); |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 51 | int ret = 0; |
| 52 | |
Simon Glass | d2caf7b | 2020-02-03 07:36:14 -0700 | [diff] [blame] | 53 | plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH); |
| 54 | plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT); |
| 55 | plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 56 | uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8; |
| 57 | debug("%s: Frame buffer size %x\n", __func__, uc_plat->size); |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 58 | |
| 59 | return ret; |
| 60 | } |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 61 | |
| 62 | static const struct udevice_id sandbox_sdl_ids[] = { |
| 63 | { .compatible = "sandbox,lcd-sdl" }, |
| 64 | { } |
| 65 | }; |
| 66 | |
| 67 | U_BOOT_DRIVER(sdl_sandbox) = { |
| 68 | .name = "sdl_sandbox", |
| 69 | .id = UCLASS_VIDEO, |
| 70 | .of_match = sandbox_sdl_ids, |
| 71 | .bind = sandbox_sdl_bind, |
| 72 | .probe = sandbox_sdl_probe, |
| 73 | .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat), |
| 74 | }; |