blob: 858d7942fed5fdf6610fb485a1ef6e704634abed [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
Simon Glass057427c2020-09-22 12:45:03 -06006#define LOG_CATEGORY UCLASS_VIDEO
7
Bin Meng1b35bc52017-08-15 22:41:56 -07008#include <common.h>
9#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Bin Meng1b35bc52017-08-15 22:41:56 -070012#include <vbe.h>
13#include <video.h>
Simon Glass057427c2020-09-22 12:45:03 -060014#include <acpi/acpi_table.h>
Simon Glass8965ef22019-12-06 21:42:16 -070015#include <asm/fsp/fsp_support.h>
Simon Glass057427c2020-09-22 12:45:03 -060016#include <asm/intel_opregion.h>
Simon Glassadee5ea2019-12-06 21:42:19 -070017#include <asm/mtrr.h>
Simon Glass057427c2020-09-22 12:45:03 -060018#include <dm/acpi.h>
Bin Meng1b35bc52017-08-15 22:41:56 -070019
20DECLARE_GLOBAL_DATA_PTR;
21
22struct pixel {
23 u8 pos;
24 u8 size;
25};
26
27static const struct fsp_framebuffer {
28 struct pixel red;
29 struct pixel green;
30 struct pixel blue;
31 struct pixel rsvd;
32} fsp_framebuffer_format_map[] = {
33 [pixel_rgbx_8bpc] = { {0, 8}, {8, 8}, {16, 8}, {24, 8} },
34 [pixel_bgrx_8bpc] = { {16, 8}, {8, 8}, {0, 8}, {24, 8} },
35};
36
37static int save_vesa_mode(struct vesa_mode_info *vesa)
38{
39 const struct hob_graphics_info *ginfo;
40 const struct fsp_framebuffer *fbinfo;
41
42 ginfo = fsp_get_graphics_info(gd->arch.hob_list, NULL);
43
44 /*
45 * If there is no graphics info structure, bail out and keep
46 * running on the serial console.
Bin Meng22fc2b62017-10-18 18:20:59 -070047 *
48 * Note: on some platforms (eg: Braswell), the FSP will not produce
49 * the graphics info HOB unless you plug some cables to the display
50 * interface (eg: HDMI) on the board.
Bin Meng1b35bc52017-08-15 22:41:56 -070051 */
52 if (!ginfo) {
53 debug("FSP graphics hand-off block not found\n");
54 return -ENXIO;
55 }
56
57 vesa->x_resolution = ginfo->width;
58 vesa->y_resolution = ginfo->height;
59 vesa->bits_per_pixel = 32;
60 vesa->bytes_per_scanline = ginfo->pixels_per_scanline * 4;
61 vesa->phys_base_ptr = ginfo->fb_base;
62
63 if (ginfo->pixel_format >= pixel_bitmask) {
64 debug("FSP set unknown framebuffer format: %d\n",
65 ginfo->pixel_format);
66 return -EINVAL;
67 }
68 fbinfo = &fsp_framebuffer_format_map[ginfo->pixel_format];
69 vesa->red_mask_size = fbinfo->red.size;
70 vesa->red_mask_pos = fbinfo->red.pos;
71 vesa->green_mask_size = fbinfo->green.size;
72 vesa->green_mask_pos = fbinfo->green.pos;
73 vesa->blue_mask_size = fbinfo->blue.size;
74 vesa->blue_mask_pos = fbinfo->blue.pos;
75 vesa->reserved_mask_size = fbinfo->rsvd.size;
76 vesa->reserved_mask_pos = fbinfo->rsvd.pos;
77
78 return 0;
79}
80
81static int fsp_video_probe(struct udevice *dev)
82{
83 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
84 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
85 struct vesa_mode_info *vesa = &mode_info.vesa;
86 int ret;
87
Simon Glassd89c4a32020-04-26 09:12:53 -060088 if (!ll_boot_init())
89 return 0;
90
Bin Meng1b35bc52017-08-15 22:41:56 -070091 printf("Video: ");
92
93 /* Initialize vesa_mode_info structure */
94 ret = save_vesa_mode(vesa);
95 if (ret)
96 goto err;
97
98 /*
99 * The framebuffer base address in the FSP graphics info HOB reflects
100 * the value assigned by the FSP. After PCI enumeration the framebuffer
101 * base address may be relocated. Let's get the updated one from device.
102 *
103 * For IGD, it seems to be always on BAR2.
104 */
105 vesa->phys_base_ptr = dm_pci_read_bar32(dev, 2);
Simon Glassb3279f32020-05-10 14:17:02 -0600106 gd->fb_base = vesa->phys_base_ptr;
Bin Meng1b35bc52017-08-15 22:41:56 -0700107
108 ret = vbe_setup_video_priv(vesa, uc_priv, plat);
109 if (ret)
110 goto err;
111
Simon Glassadee5ea2019-12-06 21:42:19 -0700112 mtrr_add_request(MTRR_TYPE_WRCOMB, vesa->phys_base_ptr, 256 << 20);
113 mtrr_commit(true);
114
Simon Glassb3279f32020-05-10 14:17:02 -0600115 printf("%dx%dx%d @ %x\n", uc_priv->xsize, uc_priv->ysize,
116 vesa->bits_per_pixel, vesa->phys_base_ptr);
Bin Meng1b35bc52017-08-15 22:41:56 -0700117
118 return 0;
119
120err:
121 printf("No video mode configured in FSP!\n");
122 return ret;
123}
124
Simon Glass3ce7f242020-07-02 21:12:31 -0600125static int fsp_video_bind(struct udevice *dev)
126{
127 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
128
129 /* Set the maximum supported resolution */
130 plat->size = 2560 * 1600 * 4;
131
132 return 0;
133}
134
Simon Glass057427c2020-09-22 12:45:03 -0600135#ifdef CONFIG_INTEL_GMA_ACPI
136static int fsp_video_acpi_write_tables(const struct udevice *dev,
137 struct acpi_ctx *ctx)
138{
139 struct igd_opregion *opregion;
140 int ret;
141
142 printf("ACPI: * IGD OpRegion\n");
143 opregion = (struct igd_opregion *)ctx->current;
144
145 ret = intel_gma_init_igd_opregion((struct udevice *)dev, opregion);
146 if (ret)
147 return ret;
148
149 acpi_inc_align(ctx, sizeof(struct igd_opregion));
150
151 return 0;
152}
153#endif
154
155struct acpi_ops fsp_video_acpi_ops = {
156#ifdef CONFIG_INTEL_GMA_ACPI
157 .write_tables = fsp_video_acpi_write_tables,
158#endif
159};
160
Bin Meng1b35bc52017-08-15 22:41:56 -0700161static const struct udevice_id fsp_video_ids[] = {
162 { .compatible = "fsp-fb" },
163 { }
164};
165
166U_BOOT_DRIVER(fsp_video) = {
167 .name = "fsp_video",
168 .id = UCLASS_VIDEO,
169 .of_match = fsp_video_ids,
Simon Glass3ce7f242020-07-02 21:12:31 -0600170 .bind = fsp_video_bind,
Bin Meng1b35bc52017-08-15 22:41:56 -0700171 .probe = fsp_video_probe,
Simon Glass3ce7f242020-07-02 21:12:31 -0600172 .flags = DM_FLAG_PRE_RELOC,
Simon Glass057427c2020-09-22 12:45:03 -0600173 ACPI_OPS_PTR(&fsp_video_acpi_ops)
Bin Meng1b35bc52017-08-15 22:41:56 -0700174};
175
176static struct pci_device_id fsp_video_supported[] = {
177 { PCI_DEVICE_CLASS(PCI_CLASS_DISPLAY_VGA << 8, 0xffff00) },
178 { },
179};
180
181U_BOOT_PCI_DEVICE(fsp_video, fsp_video_supported);