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