blob: 47f824a726b137e60b3027cd03b263459f5a9851 [file] [log] [blame]
Simon Glass42bf3ee2014-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 },
Simon Glassed2d9132015-01-27 22:13:29 -070026 { .vendor = 0x8086, .device = 0x0f31 },
Simon Glass42bf3ee2014-12-29 19:32:28 -070027 {},
28};
29
30void *video_hw_init(void)
31{
32 GraphicDevice *gdev = &ctfb;
33 int bits_per_pixel;
34 pci_dev_t dev;
35 int ret;
36
37 printf("Video: ");
38 if (vbe_get_video_info(gdev)) {
39 /* TODO: Should we look these up by class? */
40 dev = pci_find_devices(vesa_video_ids, 0);
41 if (dev == -1) {
42 printf("no card detected\n");
43 return NULL;
44 }
Simon Glassf8bccd12015-01-27 22:13:35 -070045 bootstage_start(BOOTSTAGE_ID_ACCUM_LCD, "vesa display");
Simon Glass684818d2015-01-27 22:13:34 -070046 ret = pci_run_vga_bios(dev, NULL, PCI_ROM_USE_NATIVE |
47 PCI_ROM_ALLOW_FALLBACK);
Simon Glassf8bccd12015-01-27 22:13:35 -070048 bootstage_accum(BOOTSTAGE_ID_ACCUM_LCD);
Simon Glass42bf3ee2014-12-29 19:32:28 -070049 if (ret) {
50 printf("failed to run video BIOS: %d\n", ret);
51 return NULL;
52 }
53 }
54
55 if (vbe_get_video_info(gdev)) {
56 printf("No video mode configured\n");
57 return NULL;
58 }
59
60 bits_per_pixel = gdev->gdfBytesPP * 8;
61 sprintf(gdev->modeIdent, "%dx%dx%d", gdev->winSizeX, gdev->winSizeY,
62 bits_per_pixel);
63 printf("%s\n", gdev->modeIdent);
Simon Glass684818d2015-01-27 22:13:34 -070064 debug("Frame buffer at %x\n", gdev->pciBase);
Simon Glass42bf3ee2014-12-29 19:32:28 -070065
66 return (void *)gdev;
67}