Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | cafe871 | 2022-07-30 15:52:04 -0600 | [diff] [blame] | 9 | #include <vesa.h> |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 10 | #include <video.h> |
Simon Glass | e35b649 | 2021-03-15 18:00:18 +1300 | [diff] [blame] | 11 | #include <asm/cb_sysinfo.h> |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 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) |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 21 | return log_msg_ret("save", -ENXIO); |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 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 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 42 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 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 | |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 48 | if (ll_boot_init()) |
| 49 | return log_msg_ret("ll", -ENODEV); |
| 50 | |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 51 | printf("Video: "); |
| 52 | |
| 53 | /* Initialize vesa_mode_info structure */ |
| 54 | ret = save_vesa_mode(fb, vesa); |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 55 | if (ret) { |
| 56 | ret = log_msg_ret("save", ret); |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 57 | goto err; |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 58 | } |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 59 | |
Simon Glass | 644e614 | 2023-03-10 12:47:13 -0800 | [diff] [blame] | 60 | ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat); |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 61 | if (ret) { |
| 62 | ret = log_msg_ret("setup", ret); |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 63 | goto err; |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 64 | } |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 65 | |
| 66 | printf("%dx%dx%d\n", uc_priv->xsize, uc_priv->ysize, |
| 67 | vesa->bits_per_pixel); |
| 68 | |
| 69 | return 0; |
| 70 | |
| 71 | err: |
Simon Glass | 19987c9 | 2021-03-15 18:00:27 +1300 | [diff] [blame] | 72 | printf("No video mode configured in coreboot (err=%d)\n", ret); |
Bin Meng | 13b2bfc | 2016-10-09 04:14:16 -0700 | [diff] [blame] | 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static const struct udevice_id coreboot_video_ids[] = { |
| 77 | { .compatible = "coreboot-fb" }, |
| 78 | { } |
| 79 | }; |
| 80 | |
| 81 | U_BOOT_DRIVER(coreboot_video) = { |
| 82 | .name = "coreboot_video", |
| 83 | .id = UCLASS_VIDEO, |
| 84 | .of_match = coreboot_video_ids, |
| 85 | .probe = coreboot_video_probe, |
| 86 | }; |