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