coreboot.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <init.h>
  8. #include <vbe.h>
  9. #include <video.h>
  10. #include <asm/cb_sysinfo.h>
  11. static int save_vesa_mode(struct cb_framebuffer *fb,
  12. struct vesa_mode_info *vesa)
  13. {
  14. /*
  15. * If there is no framebuffer structure, bail out and keep
  16. * running on the serial console.
  17. */
  18. if (!fb)
  19. return log_msg_ret("save", -ENXIO);
  20. vesa->x_resolution = fb->x_resolution;
  21. vesa->y_resolution = fb->y_resolution;
  22. vesa->bits_per_pixel = fb->bits_per_pixel;
  23. vesa->bytes_per_scanline = fb->bytes_per_line;
  24. vesa->phys_base_ptr = fb->physical_address;
  25. vesa->red_mask_size = fb->red_mask_size;
  26. vesa->red_mask_pos = fb->red_mask_pos;
  27. vesa->green_mask_size = fb->green_mask_size;
  28. vesa->green_mask_pos = fb->green_mask_pos;
  29. vesa->blue_mask_size = fb->blue_mask_size;
  30. vesa->blue_mask_pos = fb->blue_mask_pos;
  31. vesa->reserved_mask_size = fb->reserved_mask_size;
  32. vesa->reserved_mask_pos = fb->reserved_mask_pos;
  33. return 0;
  34. }
  35. static int coreboot_video_probe(struct udevice *dev)
  36. {
  37. struct video_uc_plat *plat = dev_get_uclass_plat(dev);
  38. struct video_priv *uc_priv = dev_get_uclass_priv(dev);
  39. struct cb_framebuffer *fb = lib_sysinfo.framebuffer;
  40. struct vesa_mode_info *vesa = &mode_info.vesa;
  41. int ret;
  42. if (ll_boot_init())
  43. return log_msg_ret("ll", -ENODEV);
  44. printf("Video: ");
  45. /* Initialize vesa_mode_info structure */
  46. ret = save_vesa_mode(fb, vesa);
  47. if (ret) {
  48. ret = log_msg_ret("save", ret);
  49. goto err;
  50. }
  51. ret = vbe_setup_video_priv(vesa, uc_priv, plat);
  52. if (ret) {
  53. ret = log_msg_ret("setup", ret);
  54. goto err;
  55. }
  56. printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
  57. vesa->bits_per_pixel);
  58. return 0;
  59. err:
  60. printf("No video mode configured in coreboot (err=%d)\n", ret);
  61. return ret;
  62. }
  63. static const struct udevice_id coreboot_video_ids[] = {
  64. { .compatible = "coreboot-fb" },
  65. { }
  66. };
  67. U_BOOT_DRIVER(coreboot_video) = {
  68. .name = "coreboot_video",
  69. .id = UCLASS_VIDEO,
  70. .of_match = coreboot_video_ids,
  71. .probe = coreboot_video_probe,
  72. };