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