blob: 5b718ae3e5a5e409486b756348cabde4b9c57ed8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Menga0676be2016-10-09 04:14:16 -07002/*
3 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
Bin Menga0676be2016-10-09 04:14:16 -07004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glassd2398ab2021-03-15 18:00:27 +13008#include <init.h>
Simon Glassec86bc62022-07-30 15:52:04 -06009#include <vesa.h>
Bin Menga0676be2016-10-09 04:14:16 -070010#include <video.h>
Simon Glass9a01fd92021-03-15 18:00:18 +130011#include <asm/cb_sysinfo.h>
Bin Menga0676be2016-10-09 04:14:16 -070012
13static int save_vesa_mode(struct cb_framebuffer *fb,
14 struct vesa_mode_info *vesa)
15{
16 /*
17 * If there is no framebuffer structure, bail out and keep
18 * running on the serial console.
19 */
20 if (!fb)
Simon Glassd2398ab2021-03-15 18:00:27 +130021 return log_msg_ret("save", -ENXIO);
Bin Menga0676be2016-10-09 04:14:16 -070022
23 vesa->x_resolution = fb->x_resolution;
24 vesa->y_resolution = fb->y_resolution;
25 vesa->bits_per_pixel = fb->bits_per_pixel;
26 vesa->bytes_per_scanline = fb->bytes_per_line;
27 vesa->phys_base_ptr = fb->physical_address;
28 vesa->red_mask_size = fb->red_mask_size;
29 vesa->red_mask_pos = fb->red_mask_pos;
30 vesa->green_mask_size = fb->green_mask_size;
31 vesa->green_mask_pos = fb->green_mask_pos;
32 vesa->blue_mask_size = fb->blue_mask_size;
33 vesa->blue_mask_pos = fb->blue_mask_pos;
34 vesa->reserved_mask_size = fb->reserved_mask_size;
35 vesa->reserved_mask_pos = fb->reserved_mask_pos;
36
37 return 0;
38}
39
40static int coreboot_video_probe(struct udevice *dev)
41{
Simon Glassb75b15b2020-12-03 16:55:23 -070042 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Bin Menga0676be2016-10-09 04:14:16 -070043 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
44 struct cb_framebuffer *fb = lib_sysinfo.framebuffer;
45 struct vesa_mode_info *vesa = &mode_info.vesa;
46 int ret;
47
Simon Glassd2398ab2021-03-15 18:00:27 +130048 if (ll_boot_init())
49 return log_msg_ret("ll", -ENODEV);
50
Bin Menga0676be2016-10-09 04:14:16 -070051 printf("Video: ");
52
53 /* Initialize vesa_mode_info structure */
54 ret = save_vesa_mode(fb, vesa);
Simon Glassd2398ab2021-03-15 18:00:27 +130055 if (ret) {
56 ret = log_msg_ret("save", ret);
Bin Menga0676be2016-10-09 04:14:16 -070057 goto err;
Simon Glassd2398ab2021-03-15 18:00:27 +130058 }
Bin Menga0676be2016-10-09 04:14:16 -070059
Simon Glassc1e9eab2023-03-10 12:47:13 -080060 ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
Simon Glassd2398ab2021-03-15 18:00:27 +130061 if (ret) {
62 ret = log_msg_ret("setup", ret);
Bin Menga0676be2016-10-09 04:14:16 -070063 goto err;
Simon Glassd2398ab2021-03-15 18:00:27 +130064 }
Bin Menga0676be2016-10-09 04:14:16 -070065
66 printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
67 vesa->bits_per_pixel);
68
69 return 0;
70
71err:
Simon Glassd2398ab2021-03-15 18:00:27 +130072 printf("No video mode configured in coreboot (err=%d)\n", ret);
Bin Menga0676be2016-10-09 04:14:16 -070073 return ret;
74}
75
Simon Glasse96ac572023-09-19 21:00:11 -060076static int coreboot_video_bind(struct udevice *dev)
77{
78 struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
79
80 /* Set the maximum supported resolution */
81 uc_plat->size = 4096 * 2160 * 4;
82 log_debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
83
84 return 0;
85}
86
Bin Menga0676be2016-10-09 04:14:16 -070087static const struct udevice_id coreboot_video_ids[] = {
88 { .compatible = "coreboot-fb" },
89 { }
90};
91
92U_BOOT_DRIVER(coreboot_video) = {
93 .name = "coreboot_video",
94 .id = UCLASS_VIDEO,
95 .of_match = coreboot_video_ids,
Simon Glasse96ac572023-09-19 21:00:11 -060096 .bind = coreboot_video_bind,
Bin Menga0676be2016-10-09 04:14:16 -070097 .probe = coreboot_video_probe,
98};