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 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 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 | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 12 | #include <asm/sdl.h> |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 13 | #include <asm/state.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 14 | #include <asm/u-boot-sandbox.h> |
Simon Glass | c3b5adf | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 15 | #include <dm/device-internal.h> |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 16 | #include <dm/test.h> |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | enum { |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 21 | /* Default LCD size we support */ |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 22 | LCD_MAX_WIDTH = 1366, |
| 23 | LCD_MAX_HEIGHT = 768, |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 26 | static int sandbox_sdl_probe(struct udevice *dev) |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 27 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 28 | struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 29 | struct sandbox_sdl_plat *plat = dev_get_plat(dev); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 30 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 31 | struct sandbox_state *state = state_get_current(); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 32 | int ret; |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 33 | |
Simon Glass | f91de0b | 2020-02-03 07:36:13 -0700 | [diff] [blame] | 34 | ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix, |
| 35 | state->double_lcd); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 36 | if (ret) { |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 37 | puts("LCD init failed\n"); |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 38 | return ret; |
| 39 | } |
| 40 | uc_priv->xsize = plat->xres; |
| 41 | uc_priv->ysize = plat->yres; |
| 42 | uc_priv->bpix = plat->bpix; |
| 43 | uc_priv->rot = plat->rot; |
Simon Glass | 69f617f | 2016-01-14 18:10:49 -0700 | [diff] [blame] | 44 | uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name; |
| 45 | uc_priv->font_size = plat->font_size; |
Simon Glass | 2a0f8e3 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 46 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) |
Simon Glass | a45738a | 2021-11-19 13:23:49 -0700 | [diff] [blame] | 47 | uc_plat->copy_base = uc_plat->base + uc_plat->size / 2; |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 48 | |
| 49 | return 0; |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Simon Glass | c3cfd76 | 2021-11-19 13:23:45 -0700 | [diff] [blame] | 52 | static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp) |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 53 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 54 | struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 55 | struct sandbox_sdl_plat *plat = dev_get_plat(dev); |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 56 | |
Simon Glass | c3cfd76 | 2021-11-19 13:23:45 -0700 | [diff] [blame] | 57 | plat->bpix = l2bpp; |
| 58 | |
Simon Glass | 0c5b59e | 2021-11-19 13:23:48 -0700 | [diff] [blame] | 59 | uc_plat->size = plat->xres * plat->yres * VNBYTES(plat->bpix); |
| 60 | |
| 61 | /* |
| 62 | * Set up to the maximum size we'll ever need. This is a strange case. |
| 63 | * The video memory is allocated by video_post_bind() called from |
| 64 | * board_init_r(). If a test changes the reoslution so it needs more |
| 65 | * memory later (with sandbox_sdl_set_bpp()), it is too late to make |
| 66 | * the frame buffer larger. |
| 67 | * |
| 68 | * So use a maximum size here. |
| 69 | */ |
| 70 | uc_plat->size = max(uc_plat->size, 1920U * 1080 * VNBYTES(VIDEO_BPP32)); |
Simon Glass | 2a0f8e3 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 71 | |
| 72 | /* Allow space for two buffers, the lower one being the copy buffer */ |
| 73 | log_debug("Frame buffer size %x\n", uc_plat->size); |
Simon Glass | 0c5b59e | 2021-11-19 13:23:48 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * If a copy framebuffer is used, double the size and use the last half |
| 77 | * as the copy, with the first half as the normal frame buffer. |
| 78 | */ |
Simon Glass | 2a0f8e3 | 2020-07-02 21:12:29 -0600 | [diff] [blame] | 79 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) |
| 80 | uc_plat->size *= 2; |
Simon Glass | c3cfd76 | 2021-11-19 13:23:45 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Simon Glass | c3b5adf | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 83 | int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp) |
| 84 | { |
Simon Glass | 87a3cd7 | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 85 | struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | c3b5adf | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 86 | int ret; |
| 87 | |
| 88 | if (device_active(dev)) |
| 89 | return -EINVAL; |
| 90 | sandbox_sdl_remove_display(); |
| 91 | |
Simon Glass | 87a3cd7 | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 92 | uc_plat->hide_logo = true; |
Simon Glass | c3b5adf | 2021-11-19 13:23:50 -0700 | [diff] [blame] | 93 | set_bpp(dev, l2bpp); |
| 94 | |
| 95 | ret = device_probe(dev); |
| 96 | if (ret) |
| 97 | return ret; |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Simon Glass | cce7480 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 102 | static int sandbox_sdl_remove(struct udevice *dev) |
| 103 | { |
| 104 | /* |
| 105 | * Removing the display it a bit annoying when running unit tests, since |
| 106 | * they remove all devices. It is nice to be able to see what the test |
| 107 | * wrote onto the display. So this comment is just here to show how to |
| 108 | * do it, if we want to make it optional one day. |
| 109 | * |
| 110 | * sandbox_sdl_remove_display(); |
| 111 | */ |
Simon Glass | cce7480 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
Simon Glass | c3cfd76 | 2021-11-19 13:23:45 -0700 | [diff] [blame] | 115 | static int sandbox_sdl_bind(struct udevice *dev) |
| 116 | { |
| 117 | struct sandbox_sdl_plat *plat = dev_get_plat(dev); |
| 118 | enum video_log2_bpp l2bpp; |
| 119 | int ret = 0; |
| 120 | |
| 121 | plat->xres = dev_read_u32_default(dev, "xres", LCD_MAX_WIDTH); |
| 122 | plat->yres = dev_read_u32_default(dev, "yres", LCD_MAX_HEIGHT); |
| 123 | l2bpp = dev_read_u32_default(dev, "log2-depth", VIDEO_BPP16); |
| 124 | plat->rot = dev_read_u32_default(dev, "rotate", 0); |
| 125 | |
| 126 | set_bpp(dev, l2bpp); |
Simon Glass | b9ddbf4 | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 127 | |
| 128 | return ret; |
| 129 | } |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 130 | |
| 131 | static const struct udevice_id sandbox_sdl_ids[] = { |
| 132 | { .compatible = "sandbox,lcd-sdl" }, |
| 133 | { } |
| 134 | }; |
| 135 | |
Walter Lozano | 2901ac6 | 2020-06-25 01:10:04 -0300 | [diff] [blame] | 136 | U_BOOT_DRIVER(sandbox_lcd_sdl) = { |
| 137 | .name = "sandbox_lcd_sdl", |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 138 | .id = UCLASS_VIDEO, |
| 139 | .of_match = sandbox_sdl_ids, |
| 140 | .bind = sandbox_sdl_bind, |
| 141 | .probe = sandbox_sdl_probe, |
Simon Glass | cce7480 | 2021-11-19 13:23:46 -0700 | [diff] [blame] | 142 | .remove = sandbox_sdl_remove, |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 143 | .plat_auto = sizeof(struct sandbox_sdl_plat), |
Simon Glass | 38a2ae2 | 2016-01-18 19:52:25 -0700 | [diff] [blame] | 144 | }; |