blob: 5f7701265a95340dca95ceb8bfa8188c1260af18 [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 <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glassec86bc62022-07-30 15:52:04 -060011#include <vesa.h>
Bin Meng1b35bc52017-08-15 22:41:56 -070012#include <video.h>
Simon Glass057427c2020-09-22 12:45:03 -060013#include <acpi/acpi_table.h>
Simon Glass8965ef22019-12-06 21:42:16 -070014#include <asm/fsp/fsp_support.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.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{
Simon Glassb75b15b2020-12-03 16:55:23 -070083 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Bin Meng1b35bc52017-08-15 22:41:56 -070084 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())
Simon Glassee3ea442021-03-15 18:00:28 +130089 return -ENODEV;
Simon Glassd89c4a32020-04-26 09:12:53 -060090
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
Simon Glassc1e9eab2023-03-10 12:47:13 -0800108 ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
Bin Meng1b35bc52017-08-15 22:41:56 -0700109 if (ret)
110 goto err;
111
Bin Mengdef9b882023-07-31 14:01:04 +0800112 mtrr_set_next_var(MTRR_TYPE_WRCOMB, vesa->phys_base_ptr, 256 << 20);
Simon Glassadee5ea2019-12-06 21:42:19 -0700113
Simon Glassb3279f32020-05-10 14:17:02 -0600114 printf("%dx%dx%d @ %x\n", uc_priv->xsize, uc_priv->ysize,
115 vesa->bits_per_pixel, vesa->phys_base_ptr);
Bin Meng1b35bc52017-08-15 22:41:56 -0700116
117 return 0;
118
119err:
120 printf("No video mode configured in FSP!\n");
121 return ret;
122}
123
Simon Glass3ce7f242020-07-02 21:12:31 -0600124static int fsp_video_bind(struct udevice *dev)
125{
Simon Glassb75b15b2020-12-03 16:55:23 -0700126 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glass3ce7f242020-07-02 21:12:31 -0600127
128 /* Set the maximum supported resolution */
129 plat->size = 2560 * 1600 * 4;
130
131 return 0;
132}
133
Simon Glass057427c2020-09-22 12:45:03 -0600134#ifdef CONFIG_INTEL_GMA_ACPI
135static int fsp_video_acpi_write_tables(const struct udevice *dev,
136 struct acpi_ctx *ctx)
137{
138 struct igd_opregion *opregion;
139 int ret;
140
Simon Glassdd5fa062020-11-04 09:57:39 -0700141 log_debug("ACPI: * IGD OpRegion\n");
Simon Glass057427c2020-09-22 12:45:03 -0600142 opregion = (struct igd_opregion *)ctx->current;
143
144 ret = intel_gma_init_igd_opregion((struct udevice *)dev, opregion);
145 if (ret)
146 return ret;
147
148 acpi_inc_align(ctx, sizeof(struct igd_opregion));
149
150 return 0;
151}
152#endif
153
154struct acpi_ops fsp_video_acpi_ops = {
155#ifdef CONFIG_INTEL_GMA_ACPI
156 .write_tables = fsp_video_acpi_write_tables,
157#endif
158};
159
Bin Meng1b35bc52017-08-15 22:41:56 -0700160static const struct udevice_id fsp_video_ids[] = {
161 { .compatible = "fsp-fb" },
162 { }
163};
164
165U_BOOT_DRIVER(fsp_video) = {
166 .name = "fsp_video",
167 .id = UCLASS_VIDEO,
168 .of_match = fsp_video_ids,
Simon Glass3ce7f242020-07-02 21:12:31 -0600169 .bind = fsp_video_bind,
Bin Meng1b35bc52017-08-15 22:41:56 -0700170 .probe = fsp_video_probe,
Simon Glass3ce7f242020-07-02 21:12:31 -0600171 .flags = DM_FLAG_PRE_RELOC,
Simon Glass057427c2020-09-22 12:45:03 -0600172 ACPI_OPS_PTR(&fsp_video_acpi_ops)
Bin Meng1b35bc52017-08-15 22:41:56 -0700173};
174
175static struct pci_device_id fsp_video_supported[] = {
176 { PCI_DEVICE_CLASS(PCI_CLASS_DISPLAY_VGA << 8, 0xffff00) },
177 { },
178};
179
180U_BOOT_PCI_DEVICE(fsp_video, fsp_video_supported);