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