xref: /openbmc/u-boot/drivers/video/coreboot.c (revision ebce73f0)
1 /*
2  * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <vbe.h>
10 #include <video.h>
11 #include <asm/arch/sysinfo.h>
12 
13 static 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)
21 		return -ENXIO;
22 
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 
40 static int coreboot_video_probe(struct udevice *dev)
41 {
42 	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
43 	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 
48 	printf("Video: ");
49 
50 	/* Initialize vesa_mode_info structure */
51 	ret = save_vesa_mode(fb, vesa);
52 	if (ret)
53 		goto err;
54 
55 	ret = vbe_setup_video_priv(vesa, uc_priv, plat);
56 	if (ret)
57 		goto err;
58 
59 	printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize,
60 	       vesa->bits_per_pixel);
61 
62 	return 0;
63 
64 err:
65 	printf("No video mode configured in coreboot!\n");
66 	return ret;
67 }
68 
69 static const struct udevice_id coreboot_video_ids[] = {
70 	{ .compatible = "coreboot-fb" },
71 	{ }
72 };
73 
74 U_BOOT_DRIVER(coreboot_video) = {
75 	.name	= "coreboot_video",
76 	.id	= UCLASS_VIDEO,
77 	.of_match = coreboot_video_ids,
78 	.probe	= coreboot_video_probe,
79 };
80