blob: 0e71583a49f423d2e3582030158dd6f32e2292a4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng1b35bc52017-08-15 22:41:56 -07002/*
3 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
Bin Meng1b35bc52017-08-15 22:41:56 -07004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Bin Meng1b35bc52017-08-15 22:41:56 -07009#include <vbe.h>
10#include <video.h>
Simon Glass8965ef22019-12-06 21:42:16 -070011#include <asm/fsp/fsp_support.h>
Simon Glassadee5ea2019-12-06 21:42:19 -070012#include <asm/mtrr.h>
Bin Meng1b35bc52017-08-15 22:41:56 -070013
14DECLARE_GLOBAL_DATA_PTR;
15
16struct pixel {
17 u8 pos;
18 u8 size;
19};
20
21static const struct fsp_framebuffer {
22 struct pixel red;
23 struct pixel green;
24 struct pixel blue;
25 struct pixel rsvd;
26} fsp_framebuffer_format_map[] = {
27 [pixel_rgbx_8bpc] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
28 [pixel_bgrx_8bpc] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
29};
30
31static int save_vesa_mode(struct vesa_mode_info *vesa)
32{
33 const struct hob_graphics_info *ginfo;
34 const struct fsp_framebuffer *fbinfo;
35
36 ginfo = fsp_get_graphics_info(gd->arch.hob_list, NULL);
37
38 /*
39 * If there is no graphics info structure, bail out and keep
40 * running on the serial console.
Bin Meng22fc2b62017-10-18 18:20:59 -070041 *
42 * Note: on some platforms (eg: Braswell), the FSP will not produce
43 * the graphics info HOB unless you plug some cables to the display
44 * interface (eg: HDMI) on the board.
Bin Meng1b35bc52017-08-15 22:41:56 -070045 */
46 if (!ginfo) {
47 debug("FSP graphics hand-off block not found\n");
48 return -ENXIO;
49 }
50
51 vesa->x_resolution = ginfo->width;
52 vesa->y_resolution = ginfo->height;
53 vesa->bits_per_pixel = 32;
54 vesa->bytes_per_scanline = ginfo->pixels_per_scanline * 4;
55 vesa->phys_base_ptr = ginfo->fb_base;
56
57 if (ginfo->pixel_format >= pixel_bitmask) {
58 debug("FSP set unknown framebuffer format: %d\n",
59 ginfo->pixel_format);
60 return -EINVAL;
61 }
62 fbinfo = &fsp_framebuffer_format_map[ginfo->pixel_format];
63 vesa->red_mask_size = fbinfo->red.size;
64 vesa->red_mask_pos = fbinfo->red.pos;
65 vesa->green_mask_size = fbinfo->green.size;
66 vesa->green_mask_pos = fbinfo->green.pos;
67 vesa->blue_mask_size = fbinfo->blue.size;
68 vesa->blue_mask_pos = fbinfo->blue.pos;
69 vesa->reserved_mask_size = fbinfo->rsvd.size;
70 vesa->reserved_mask_pos = fbinfo->rsvd.pos;
71
72 return 0;
73}
74
75static int fsp_video_probe(struct udevice *dev)
76{
77 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
78 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
79 struct vesa_mode_info *vesa = &mode_info.vesa;
80 int ret;
81
Simon Glassd89c4a32020-04-26 09:12:53 -060082 if (!ll_boot_init())
83 return 0;
84
Bin Meng1b35bc52017-08-15 22:41:56 -070085 printf("Video: ");
86
87 /* Initialize vesa_mode_info structure */
88 ret = save_vesa_mode(vesa);
89 if (ret)
90 goto err;
91
92 /*
93 * The framebuffer base address in the FSP graphics info HOB reflects
94 * the value assigned by the FSP. After PCI enumeration the framebuffer
95 * base address may be relocated. Let's get the updated one from device.
96 *
97 * For IGD, it seems to be always on BAR2.
98 */
99 vesa->phys_base_ptr = dm_pci_read_bar32(dev, 2);
100
101 ret = vbe_setup_video_priv(vesa, uc_priv, plat);
102 if (ret)
103 goto err;
104
Simon Glassadee5ea2019-12-06 21:42:19 -0700105 mtrr_add_request(MTRR_TYPE_WRCOMB, vesa->phys_base_ptr, 256 << 20);
106 mtrr_commit(true);
107
Bin Meng1b35bc52017-08-15 22:41:56 -0700108 printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
109 vesa->bits_per_pixel);
110
111 return 0;
112
113err:
114 printf("No video mode configured in FSP!\n");
115 return ret;
116}
117
118static const struct udevice_id fsp_video_ids[] = {
119 { .compatible = "fsp-fb" },
120 { }
121};
122
123U_BOOT_DRIVER(fsp_video) = {
124 .name = "fsp_video",
125 .id = UCLASS_VIDEO,
126 .of_match = fsp_video_ids,
127 .probe = fsp_video_probe,
128};
129
130static struct pci_device_id fsp_video_supported[] = {
131 { PCI_DEVICE_CLASS(PCI_CLASS_DISPLAY_VGA << 8, 0xffff00) },
132 { },
133};
134
135U_BOOT_PCI_DEVICE(fsp_video, fsp_video_supported);