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 | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 10 | #include <video.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 12 | #include <asm/sdl.h> |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 13 | #include <asm/state.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 14 | #include <asm/u-boot-sandbox.h> |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 15 | #include <dm/test.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | enum { |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 20 | /* Default LCD size we support */ |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 21 | LCD_MAX_WIDTH = 1366, |
| 22 | LCD_MAX_HEIGHT = 768, |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 25 | static int sandbox_sdl_probe(struct udevice *dev) |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 26 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 27 | struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 28 | struct sandbox_sdl_plat *plat = dev_get_plat(dev); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 29 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 30 | struct sandbox_state *state = state_get_current(); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 31 | int ret; |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 32 | |
Simon Glass | 6be88c7 | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 33 | ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix, |
| 34 | state->double_lcd); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 35 | if (ret) { |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 36 | puts("LCD init failed\n"); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 37 | return ret; |
| 38 | } |
| 39 | uc_priv->xsize = plat->xres; |
| 40 | uc_priv->ysize = plat->yres; |
| 41 | uc_priv->bpix = plat->bpix; |
| 42 | uc_priv->rot = plat->rot; |
Simon Glass | 8de536c | 2016-01-14 18:10:49 -0700 | [diff] [blame] | 43 | uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name; |
| 44 | uc_priv->font_size = plat->font_size; |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 45 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) |
| 46 | uc_plat->copy_base = uc_plat->base - uc_plat->size / 2; |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 47 | |
| 48 | return 0; |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 51 | static int sandbox_sdl_bind(struct udevice *dev) |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 52 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 53 | struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 54 | struct sandbox_sdl_plat *plat = dev_get_plat(dev); |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 55 | int ret = 0; |
| 56 | |
Simon Glass | a466db5 | 2020-02-03 07:36:14 -0700 | [diff] [blame] | 57 | plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH); |
| 58 | plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT); |
| 59 | plat->bpix = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16); |
Simon Glass | 6a2ea43 | 2020-07-02 21:12:15 -0600 | [diff] [blame] | 60 | plat->rot = dev_read_u32_default(dev, "rotate", 0); |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 61 | uc_plat->size = plat->xres * plat->yres * (1 << plat->bpix) / 8; |
Simon Glass | f578ca7 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 62 | |
| 63 | /* Allow space for two buffers, the lower one being the copy buffer */ |
| 64 | log_debug("Frame buffer size %x\n", uc_plat->size); |
| 65 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) |
| 66 | uc_plat->size *= 2; |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 67 | |
| 68 | return ret; |
| 69 | } |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 70 | |
| 71 | static const struct udevice_id sandbox_sdl_ids[] = { |
| 72 | { .compatible = "sandbox,lcd-sdl" }, |
| 73 | { } |
| 74 | }; |
| 75 | |
Walter Lozano | e3e2470 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 76 | U_BOOT_DRIVER(sandbox_lcd_sdl) = { |
| 77 | .name = "sandbox_lcd_sdl", |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 78 | .id = UCLASS_VIDEO, |
| 79 | .of_match = sandbox_sdl_ids, |
| 80 | .bind = sandbox_sdl_bind, |
| 81 | .probe = sandbox_sdl_probe, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 82 | .plat_auto = sizeof(struct sandbox_sdl_plat), |
Simon Glass | 3ade5bc | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 83 | }; |