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