fsp_graphics.c 3.1 KB

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