blob: 021c1d68edfaca98bc47ffb01d0992da0dcc694a [file] [log] [blame]
Simon Glass6b1ba982014-12-29 19:32:28 -07001/*
Bin Mengb018a8c2015-07-06 16:31:26 +08002 * VESA frame buffer driver
Simon Glass6b1ba982014-12-29 19:32:28 -07003 *
4 * Copyright (C) 2014 Google, Inc
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <pci_rom.h>
11#include <video_fb.h>
12#include <vbe.h>
13
14/*
15 * The Graphic Device
16 */
17GraphicDevice ctfb;
18
Simon Glass6b1ba982014-12-29 19:32:28 -070019void *video_hw_init(void)
20{
21 GraphicDevice *gdev = &ctfb;
Simon Glass3f4e1e82015-11-29 13:17:57 -070022 struct udevice *dev;
Simon Glass6b1ba982014-12-29 19:32:28 -070023 int bits_per_pixel;
Simon Glass6b1ba982014-12-29 19:32:28 -070024 int ret;
25
26 printf("Video: ");
Simon Glassad11dbf2015-08-04 12:34:04 -060027 if (!ll_boot_init()) {
28 /*
29 * If we are running from EFI or coreboot, this driver can't
30 * work.
31 */
32 printf("Not available (previous bootloader prevents it)\n");
33 return NULL;
34 }
Simon Glass6b1ba982014-12-29 19:32:28 -070035 if (vbe_get_video_info(gdev)) {
Simon Glass3f4e1e82015-11-29 13:17:57 -070036 ret = dm_pci_find_class(PCI_CLASS_DISPLAY_VGA << 8, 0, &dev);
37 if (ret) {
Simon Glass6b1ba982014-12-29 19:32:28 -070038 printf("no card detected\n");
39 return NULL;
40 }
Simon Glassef565a52015-01-27 22:13:35 -070041 bootstage_start(BOOTSTAGE_ID_ACCUM_LCD, "vesa display");
Simon Glass3f4e1e82015-11-29 13:17:57 -070042 ret = dm_pci_run_vga_bios(dev, NULL, PCI_ROM_USE_NATIVE |
43 PCI_ROM_ALLOW_FALLBACK);
Simon Glassef565a52015-01-27 22:13:35 -070044 bootstage_accum(BOOTSTAGE_ID_ACCUM_LCD);
Simon Glass6b1ba982014-12-29 19:32:28 -070045 if (ret) {
46 printf("failed to run video BIOS: %d\n", ret);
47 return NULL;
48 }
49 }
50
51 if (vbe_get_video_info(gdev)) {
52 printf("No video mode configured\n");
53 return NULL;
54 }
55
56 bits_per_pixel = gdev->gdfBytesPP * 8;
57 sprintf(gdev->modeIdent, "%dx%dx%d", gdev->winSizeX, gdev->winSizeY,
58 bits_per_pixel);
59 printf("%s\n", gdev->modeIdent);
Simon Glassbc17d8f2015-01-27 22:13:34 -070060 debug("Frame buffer at %x\n", gdev->pciBase);
Simon Glass6b1ba982014-12-29 19:32:28 -070061
62 return (void *)gdev;
63}