Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / northbridge / intel / i82830 / vga.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 Joseph Smith <joe@settoplinux.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <console/console.h>
22 #include <arch/io.h>
23 #include <stdint.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cbfs.h>
28 #if defined(CONFIG_PCI_OPTION_ROM_RUN_YABEL) && CONFIG_PCI_OPTION_ROM_RUN_YABEL
29 #include <x86emu/x86emu.h>
30 #endif
31
32 static void vga_init(device_t dev)
33 {
34         printk(BIOS_INFO, "Starting Graphics Initialization\n");
35         struct cbfs_file *file = cbfs_find("mbi.bin");
36         void *mbi = NULL;
37         unsigned int mbi_len = 0;
38
39         if (file) {
40                 if (ntohl(file->type) != CBFS_TYPE_MBI) {
41                         printk(BIOS_INFO,  "CBFS:  MBI binary is of type %x instead of"
42                                "type %x\n", file->type, CBFS_TYPE_MBI);
43                 } else {
44                         mbi = (void *) CBFS_SUBHEADER(file);
45                         mbi_len = ntohl(file->len);
46                 }
47         } else {
48                 printk(BIOS_INFO,  "Could not find MBI.\n");
49         }
50
51         if (mbi && mbi_len) {
52                 /* The GDT or coreboot table is going to live here. But
53                  * a long time after we relocated the GNVS, so this is
54                  * not troublesome.
55                  */
56                 *(u32 *)0x500 = (u32)mbi;
57                 *(u32 *)0x504 = (u32)mbi_len;
58                 outb(0xeb, 0xb2);
59         }
60
61         pci_dev_init(dev);
62         printk(BIOS_INFO, "Graphics Initialization Complete\n");
63
64         /* Enable TV-Out */
65 #if defined(CONFIG_PCI_OPTION_ROM_RUN_YABEL) && CONFIG_PCI_OPTION_ROM_RUN_YABEL
66 #define PIPE_A_CRT      (1 << 0)
67 #define PIPE_A_LFP      (1 << 1)
68 #define PIPE_A_TV       (1 << 3)
69 #define PIPE_B_CRT      (1 << 8)
70 #define PIPE_B_TV       (1 << 10)
71         printk(BIOS_DEBUG, "Enabling TV-Out\n");
72         void runInt10(void);
73         M.x86.R_AX = 0x5f64;
74         M.x86.R_BX = 0x0001; // Set Display Device, force execution
75         M.x86.R_CX = PIPE_A_CRT | PIPE_A_TV;
76         // M.x86.R_CX = PIPE_B_TV;
77         runInt10();
78         switch (M.x86.R_AX) {
79         case 0x005f:
80                 printk(BIOS_DEBUG, "... failed.\n");
81                 break;
82         case 0x015f:
83                 printk(BIOS_DEBUG, "... ok.\n");
84                 break;
85         default:
86                 printk(BIOS_DEBUG, "... not supported.\n");
87                 break;
88         }
89 #endif
90 }
91
92 static const struct device_operations vga_operations = {
93         .read_resources   = pci_dev_read_resources,
94         .set_resources    = pci_dev_set_resources,
95         .enable_resources = pci_dev_enable_resources,
96         .init             = vga_init,
97         .scan_bus         = 0,
98         .enable           = 0,
99         .ops_pci          = 0,
100 };
101
102 static const struct pci_driver vga_driver __pci_driver = {
103         .ops    = &vga_operations,
104         .vendor = PCI_VENDOR_ID_INTEL,
105         .device = 0x3577,
106 };