Simon Glass | 6b1ba98 | 2014-12-29 19:32:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 18 | GraphicDevice ctfb; |
| 19 | |
| 20 | /* Devices to allow - only the last one works fully */ |
| 21 | struct 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 Glass | 82c2566 | 2015-01-27 22:13:29 -0700 | [diff] [blame] | 26 | { .vendor = 0x8086, .device = 0x0f31 }, |
Simon Glass | 6b1ba98 | 2014-12-29 19:32:28 -0700 | [diff] [blame] | 27 | {}, |
| 28 | }; |
| 29 | |
| 30 | void *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 Glass | ef565a5 | 2015-01-27 22:13:35 -0700 | [diff] [blame] | 45 | bootstage_start(BOOTSTAGE_ID_ACCUM_LCD, "vesa display"); |
Simon Glass | bc17d8f | 2015-01-27 22:13:34 -0700 | [diff] [blame] | 46 | ret = pci_run_vga_bios(dev, NULL, PCI_ROM_USE_NATIVE | |
| 47 | PCI_ROM_ALLOW_FALLBACK); |
Simon Glass | ef565a5 | 2015-01-27 22:13:35 -0700 | [diff] [blame] | 48 | bootstage_accum(BOOTSTAGE_ID_ACCUM_LCD); |
Simon Glass | 6b1ba98 | 2014-12-29 19:32:28 -0700 | [diff] [blame] | 49 | 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 Glass | bc17d8f | 2015-01-27 22:13:34 -0700 | [diff] [blame] | 64 | debug("Frame buffer at %x\n", gdev->pciBase); |
Simon Glass | 6b1ba98 | 2014-12-29 19:32:28 -0700 | [diff] [blame] | 65 | |
| 66 | return (void *)gdev; |
| 67 | } |