blob: 9081c7da62e4b52f1e8009b9c54d338176192618 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass7d95f2a2014-02-27 13:26:19 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glass7d95f2a2014-02-27 13:26:19 -07004 */
5
6#include <common.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -07007#include <dm.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -07008#include <fdtdec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -070010#include <video.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070012#include <asm/sdl.h>
Simon Glass6be88c72020-02-03 07:36:13 -070013#include <asm/state.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070014#include <asm/u-boot-sandbox.h>
Simon Glass8657ad42021-11-19 13:23:50 -070015#include <dm/device-internal.h>
Simon Glass3ade5bc2016-01-18 19:52:25 -070016#include <dm/test.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070017
18DECLARE_GLOBAL_DATA_PTR;
19
20enum {
Simon Glass3ade5bc2016-01-18 19:52:25 -070021 /* Default LCD size we support */
Simon Glass7d95f2a2014-02-27 13:26:19 -070022 LCD_MAX_WIDTH = 1366,
23 LCD_MAX_HEIGHT = 768,
Simon Glass7d95f2a2014-02-27 13:26:19 -070024};
25
Simon Glass3ade5bc2016-01-18 19:52:25 -070026static int sandbox_sdl_probe(struct udevice *dev)
Simon Glass7d95f2a2014-02-27 13:26:19 -070027{
Simon Glass8a8d24b2020-12-03 16:55:23 -070028 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glassc69cda22020-12-03 16:55:20 -070029 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
Simon Glass3ade5bc2016-01-18 19:52:25 -070030 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glass6be88c72020-02-03 07:36:13 -070031 struct sandbox_state *state = state_get_current();
Simon Glass3ade5bc2016-01-18 19:52:25 -070032 int ret;
Simon Glass7d95f2a2014-02-27 13:26:19 -070033
Simon Glass6be88c72020-02-03 07:36:13 -070034 ret = sandbox_sdl_init_display(plat->xres, plat->yres, plat->bpix,
35 state->double_lcd);
Simon Glass3ade5bc2016-01-18 19:52:25 -070036 if (ret) {
Simon Glass7d95f2a2014-02-27 13:26:19 -070037 puts("LCD init failed\n");
Simon Glass3ade5bc2016-01-18 19:52:25 -070038 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 Glass8de536c2016-01-14 18:10:49 -070044 uc_priv->vidconsole_drv_name = plat->vidconsole_drv_name;
45 uc_priv->font_size = plat->font_size;
Simon Glassf578ca72020-07-02 21:12:29 -060046 if (IS_ENABLED(CONFIG_VIDEO_COPY))
Simon Glass84051742021-11-19 13:23:49 -070047 uc_plat->copy_base = uc_plat->base + uc_plat->size / 2;
Simon Glass3ade5bc2016-01-18 19:52:25 -070048
49 return 0;
Simon Glass7d95f2a2014-02-27 13:26:19 -070050}
51
Simon Glass0fe5e942021-11-19 13:23:45 -070052static void set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
Simon Glass7d95f2a2014-02-27 13:26:19 -070053{
Simon Glass8a8d24b2020-12-03 16:55:23 -070054 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glassc69cda22020-12-03 16:55:20 -070055 struct sandbox_sdl_plat *plat = dev_get_plat(dev);
Simon Glass7d95f2a2014-02-27 13:26:19 -070056
Simon Glass0fe5e942021-11-19 13:23:45 -070057 plat->bpix = l2bpp;
58
Simon Glass301af232021-11-19 13:23:48 -070059 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 Glassf578ca72020-07-02 21:12:29 -060071
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 Glass301af232021-11-19 13:23:48 -070074
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 Glassf578ca72020-07-02 21:12:29 -060079 if (IS_ENABLED(CONFIG_VIDEO_COPY))
80 uc_plat->size *= 2;
Simon Glass0fe5e942021-11-19 13:23:45 -070081}
82
Simon Glass8657ad42021-11-19 13:23:50 -070083int sandbox_sdl_set_bpp(struct udevice *dev, enum video_log2_bpp l2bpp)
84{
Simon Glass84e63ab2021-11-19 13:24:03 -070085 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
Simon Glass8657ad42021-11-19 13:23:50 -070086 int ret;
87
88 if (device_active(dev))
89 return -EINVAL;
90 sandbox_sdl_remove_display();
91
Simon Glass84e63ab2021-11-19 13:24:03 -070092 uc_plat->hide_logo = true;
Simon Glass8657ad42021-11-19 13:23:50 -070093 set_bpp(dev, l2bpp);
94
95 ret = device_probe(dev);
96 if (ret)
97 return ret;
98
99 return 0;
100}
101
Simon Glass250e7352021-11-19 13:23:46 -0700102static 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 Glass250e7352021-11-19 13:23:46 -0700112 return 0;
113}
114
Simon Glass0fe5e942021-11-19 13:23:45 -0700115static 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 Glass7d95f2a2014-02-27 13:26:19 -0700127
128 return ret;
129}
Simon Glass3ade5bc2016-01-18 19:52:25 -0700130
131static const struct udevice_id sandbox_sdl_ids[] = {
132 { .compatible = "sandbox,lcd-sdl" },
133 { }
134};
135
Walter Lozanoe3e24702020-06-25 01:10:04 -0300136U_BOOT_DRIVER(sandbox_lcd_sdl) = {
137 .name = "sandbox_lcd_sdl",
Simon Glass3ade5bc2016-01-18 19:52:25 -0700138 .id = UCLASS_VIDEO,
139 .of_match = sandbox_sdl_ids,
140 .bind = sandbox_sdl_bind,
141 .probe = sandbox_sdl_probe,
Simon Glass250e7352021-11-19 13:23:46 -0700142 .remove = sandbox_sdl_remove,
Simon Glasscaa4daa2020-12-03 16:55:18 -0700143 .plat_auto = sizeof(struct sandbox_sdl_plat),
Simon Glass3ade5bc2016-01-18 19:52:25 -0700144};