Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 8 | #include <fdtdec.h> |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 9 | #include <video.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 10 | #include <asm/sdl.h> |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame^] | 11 | #include <asm/state.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 12 | #include <asm/u-boot-sandbox.h> |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 13 | #include <dm/test.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | enum { |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 18 | /* Default LCD size we support */ |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 19 | LCD_MAX_WIDTH = 1366, |
| 20 | LCD_MAX_HEIGHT = 768, |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 21 | }; |
| 22 | |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 23 | static int sandbox_sdl_probe(struct udevice *dev) |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 24 | { |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 25 | struct sandbox_sdl_plat *plat = dev_get_platdata(dev); |
| 26 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame^] | 27 | struct sandbox_state *state = state_get_current(); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 28 | int ret; |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 29 | |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame^] | 30 | ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix, |
| 31 | state->double_lcd); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 32 | if (ret) { |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 33 | puts("LCD init failed\n"); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 34 | return ret; |
| 35 | } |
| 36 | uc_priv->xsize = plat->xres; |
| 37 | uc_priv->ysize = plat->yres; |
| 38 | uc_priv->bpix = plat->bpix; |
| 39 | uc_priv->rot = plat->rot; |
Simon Glass | 8de536c | 2016-01-14 18:10:49 -0700 | [diff] [blame] | 40 | uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name; |
| 41 | uc_priv->font_size = plat->font_size; |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 42 | |
| 43 | return 0; |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 46 | static int sandbox_sdl_bind(struct udevice *dev) |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 47 | { |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 48 | struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev); |
| 49 | struct sandbox_sdl_plat *plat = dev_get_platdata(dev); |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 50 | const void *blob = gd->fdt_blob; |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 51 | int node = dev_of_offset(dev); |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 52 | int ret = 0; |
| 53 | |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 54 | plat->xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH); |
| 55 | plat->yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT); |
| 56 | plat->bpix = VIDEO_BPP16; |
| 57 | uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8; |
| 58 | debug("%s: Frame buffer size %x\n", __func__, uc_plat->size); |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 59 | |
| 60 | return ret; |
| 61 | } |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 62 | |
| 63 | static const struct udevice_id sandbox_sdl_ids[] = { |
| 64 | { .compatible = "sandbox,lcd-sdl" }, |
| 65 | { } |
| 66 | }; |
| 67 | |
| 68 | U_BOOT_DRIVER(sdl_sandbox) = { |
| 69 | .name = "sdl_sandbox", |
| 70 | .id = UCLASS_VIDEO, |
| 71 | .of_match = sandbox_sdl_ids, |
| 72 | .bind = sandbox_sdl_bind, |
| 73 | .probe = sandbox_sdl_probe, |
| 74 | .platdata_auto_alloc_size = sizeof(struct sandbox_sdl_plat), |
| 75 | }; |