blob: ba4578e9d1530b30fea8c65b972198f4dc61b756 [file] [log] [blame]
Simon Glass7d95f2a2014-02-27 13:26:19 -07001/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <fdtdec.h>
9#include <lcd.h>
10#include <malloc.h>
11#include <asm/sdl.h>
12#include <asm/u-boot-sandbox.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16enum {
17 /* Maximum LCD size we support */
18 LCD_MAX_WIDTH = 1366,
19 LCD_MAX_HEIGHT = 768,
20 LCD_MAX_LOG2_BPP = 4, /* 2^4 = 16 bpp */
21};
22
23vidinfo_t panel_info;
24
25void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blue)
26{
27}
28
29void lcd_ctrl_init(void *lcdbase)
30{
31 /*
32 * Allocate memory to keep BMP color conversion map. This is required
33 * for 8 bit BMPs only (hence 256 colors). If malloc fails - keep
34 * going, it is not even clear if displyaing the bitmap will be
35 * required on the way up.
36 */
37 panel_info.cmap = malloc(256 * NBITS(panel_info.vl_bpix) / 8);
38}
39
40void lcd_enable(void)
41{
42 if (sandbox_sdl_init_display(panel_info.vl_col, panel_info.vl_row,
43 panel_info.vl_bpix))
44 puts("LCD init failed\n");
45}
46
47int sandbox_lcd_sdl_early_init(void)
48{
49 const void *blob = gd->fdt_blob;
50 int xres = LCD_MAX_WIDTH, yres = LCD_MAX_HEIGHT;
51 int node;
52 int ret = 0;
53
54 /*
55 * The code in common/lcd.c does not cope with not being able to
56 * set up a frame buffer. It will just happily keep writing to
57 * invalid memory. So here we make sure that at least some buffer
58 * is available even if it actually won't be displayed.
59 */
60 node = fdtdec_next_compatible(blob, 0, COMPAT_SANDBOX_LCD_SDL);
61 if (node >= 0) {
62 xres = fdtdec_get_int(blob, node, "xres", LCD_MAX_WIDTH);
63 yres = fdtdec_get_int(blob, node, "yres", LCD_MAX_HEIGHT);
64 if (xres < 0 || xres > LCD_MAX_WIDTH) {
65 xres = LCD_MAX_WIDTH;
66 ret = -EINVAL;
67 }
68 if (yres < 0 || yres > LCD_MAX_HEIGHT) {
69 yres = LCD_MAX_HEIGHT;
70 ret = -EINVAL;
71 }
72 }
73
74 panel_info.vl_col = xres;
75 panel_info.vl_row = yres;
76 panel_info.vl_bpix = LCD_COLOR16;
77
78 return ret;
79}