blob: 3dacafd6bf595c6cfebeb6688935e5f36d98b0bd [file] [log] [blame]
Simon Glass6b1ba982014-12-29 19:32:28 -07001/*
2 *
3 * Vesa frame buffer driver for x86
4 *
5 * Copyright (C) 2014 Google, Inc
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <pci_rom.h>
12#include <video_fb.h>
13#include <vbe.h>
14
15/*
16 * The Graphic Device
17 */
18GraphicDevice ctfb;
19
20/* Devices to allow - only the last one works fully */
21struct pci_device_id vesa_video_ids[] = {
22 { .vendor = 0x102b, .device = 0x0525 },
23 { .vendor = 0x1002, .device = 0x5159 },
24 { .vendor = 0x1002, .device = 0x4752 },
25 { .vendor = 0x1002, .device = 0x5452 },
26 {},
27};
28
29void *video_hw_init(void)
30{
31 GraphicDevice *gdev = &ctfb;
32 int bits_per_pixel;
33 pci_dev_t dev;
34 int ret;
35
36 printf("Video: ");
37 if (vbe_get_video_info(gdev)) {
38 /* TODO: Should we look these up by class? */
39 dev = pci_find_devices(vesa_video_ids, 0);
40 if (dev == -1) {
41 printf("no card detected\n");
42 return NULL;
43 }
44 printf("bdf %x\n", dev);
45 ret = pci_run_vga_bios(dev, NULL, true);
46 if (ret) {
47 printf("failed to run video BIOS: %d\n", ret);
48 return NULL;
49 }
50 }
51
52 if (vbe_get_video_info(gdev)) {
53 printf("No video mode configured\n");
54 return NULL;
55 }
56
57 bits_per_pixel = gdev->gdfBytesPP * 8;
58 sprintf(gdev->modeIdent, "%dx%dx%d", gdev->winSizeX, gdev->winSizeY,
59 bits_per_pixel);
60 printf("%s\n", gdev->modeIdent);
61 debug("Framex buffer at %x\n", gdev->pciBase);
62
63 return (void *)gdev;
64}