Simon Glass | 42bf3ee | 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 | ed2d913 | 2015-01-27 22:13:29 -0700 | [diff] [blame] | 26 | { .vendor = 0x8086, .device = 0x0f31 }, |
Simon Glass | 42bf3ee | 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 | 684818d | 2015-01-27 22:13:34 -0700 | [diff] [blame^] | 45 | ret = pci_run_vga_bios(dev, NULL, PCI_ROM_USE_NATIVE | |
| 46 | PCI_ROM_ALLOW_FALLBACK); |
Simon Glass | 42bf3ee | 2014-12-29 19:32:28 -0700 | [diff] [blame] | 47 | if (ret) { |
| 48 | printf("failed to run video BIOS: %d\n", ret); |
| 49 | return NULL; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if (vbe_get_video_info(gdev)) { |
| 54 | printf("No video mode configured\n"); |
| 55 | return NULL; |
| 56 | } |
| 57 | |
| 58 | bits_per_pixel = gdev->gdfBytesPP * 8; |
| 59 | sprintf(gdev->modeIdent, "%dx%dx%d", gdev->winSizeX, gdev->winSizeY, |
| 60 | bits_per_pixel); |
| 61 | printf("%s\n", gdev->modeIdent); |
Simon Glass | 684818d | 2015-01-27 22:13:34 -0700 | [diff] [blame^] | 62 | debug("Frame buffer at %x\n", gdev->pciBase); |
Simon Glass | 42bf3ee | 2014-12-29 19:32:28 -0700 | [diff] [blame] | 63 | |
| 64 | return (void *)gdev; |
| 65 | } |