Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com> |
| 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 21 | /* |
| 22 | * Note: Some of the VGA control registers are located on the memory |
| 23 | * controller. Registers are set both in raminit.c and northbridge.c. |
| 24 | */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 25 | |
| 26 | #include <console/console.h> |
| 27 | #include <arch/io.h> |
| 28 | #include <stdint.h> |
| 29 | #include <device/device.h> |
| 30 | #include <device/pci.h> |
| 31 | #include <device/pci_ids.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 34 | #include <cpu/cpu.h> |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 35 | #include <arch/interrupt.h> |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 36 | #include "northbridge.h" |
| 37 | #include "cn700.h" |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 38 | #include <x86emu/regs.h> |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 39 | |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 40 | static int via_cn700_int15_handler(void) |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 41 | { |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 42 | int res=0; |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 43 | printk(BIOS_DEBUG, "via_cn700_int15_handler\n"); |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 44 | switch(X86_EAX & 0xffff) { |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 45 | case 0x5f19: |
| 46 | break; |
| 47 | case 0x5f18: |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 48 | X86_EAX=0x5f; |
| 49 | X86_EBX=0x545; // MCLK = 133, 32M frame buffer, 256 M main memory |
| 50 | X86_ECX=0x060; |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 51 | res=1; |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 52 | break; |
| 53 | case 0x5f00: |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 54 | X86_EAX = 0x8600; |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 55 | break; |
| 56 | case 0x5f01: |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 57 | X86_EAX = 0x5f; |
| 58 | X86_ECX = (X86_ECX & 0xffffff00 ) | 2; // panel type = 2 = 1024 * 768 |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 59 | res = 1; |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 60 | break; |
| 61 | case 0x5f02: |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 62 | X86_EAX=0x5f; |
| 63 | X86_EBX= (X86_EBX & 0xffff0000) | 2; |
| 64 | X86_ECX= (X86_ECX & 0xffff0000) | 0x401; // PAL + crt only |
| 65 | X86_EDX= (X86_EDX & 0xffff0000) | 0; // TV Layout - default |
Patrick Georgi | 503af72 | 2012-11-22 10:48:18 +0100 | [diff] [blame] | 66 | res=1; |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 67 | break; |
| 68 | case 0x5f0f: |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 69 | X86_EAX=0x860f; |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 70 | break; |
| 71 | default: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 72 | printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n", |
Patrick Georgi | 199b09c | 2012-11-22 12:46:12 +0100 | [diff] [blame] | 73 | X86_EAX & 0xffff); |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 74 | break; |
| 75 | } |
| 76 | return res; |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void vga_init(device_t dev) |
| 80 | { |
| 81 | u8 reg8; |
| 82 | |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 83 | mainboard_interrupt_handlers(0x15, &via_cn700_int15_handler); |
| 84 | |
| 85 | #undef OLD_BOCHS_METHOD |
| 86 | #ifdef OLD_BOCHS_METHOD |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 87 | print_debug("Copying BOCHS BIOS to 0xf000\n"); |
| 88 | /* |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 89 | * Copy BOCHS BIOS from 4G-CONFIG_ROM_SIZE-64k (in flash) to 0xf0000 (in RAM) |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 90 | * This is for compatibility with the VGA ROM's BIOS callbacks. |
| 91 | */ |
Stefan Reinauer | 3c8ac78 | 2010-04-03 13:33:01 +0000 | [diff] [blame] | 92 | memcpy((void *)0xf0000, (const void *)(0xffffffff - CONFIG_ROM_SIZE - 0xffff), 0x10000); |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 93 | #endif |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 94 | |
| 95 | /* Set memory rate to 200 MHz. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 96 | outb(0x3d, CRTM_INDEX); |
| 97 | reg8 = inb(CRTM_DATA); |
| 98 | reg8 &= 0x0f; |
| 99 | reg8 |= (0x1 << 4); |
| 100 | outb(0x3d, CRTM_INDEX); |
| 101 | outb(reg8, CRTM_DATA); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 102 | |
| 103 | /* Set framebuffer size. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 104 | reg8 = (CONFIG_VIDEO_MB / 4); |
| 105 | outb(0x39, SR_INDEX); |
| 106 | outb(reg8, SR_DATA); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 107 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 108 | pci_write_config8(dev, 0x04, 0x07); |
| 109 | pci_write_config8(dev, 0x0d, 0x20); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 110 | pci_write_config32(dev, 0x10, 0xf4000008); |
| 111 | pci_write_config32(dev, 0x14, 0xfb000000); |
| 112 | |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 113 | printk(BIOS_DEBUG, "Initializing VGA...\n"); |
| 114 | |
| 115 | pci_dev_init(dev); |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 116 | |
| 117 | /* It's not clear if these need to be programmed before or after |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 118 | * the VGA BIOS runs. Try both, clean up later. */ |
| 119 | /* Set memory rate to 200 MHz (again). */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 120 | outb(0x3d, CRTM_INDEX); |
| 121 | reg8 = inb(CRTM_DATA); |
| 122 | reg8 &= 0x0f; |
| 123 | reg8 |= (0x1 << 4); |
| 124 | outb(0x3d, CRTM_INDEX); |
| 125 | outb(reg8, CRTM_DATA); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 126 | |
| 127 | /* Set framebuffer size (again). */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 128 | reg8 = (CONFIG_VIDEO_MB / 4); |
| 129 | outb(0x39, SR_INDEX); |
| 130 | outb(reg8, SR_DATA); |
| 131 | |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 132 | #ifdef OLD_BOCHS_METHOD |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 133 | /* Clear the BOCHS BIOS out of memory, so it doesn't confuse Linux. */ |
Stefan Reinauer | 3c8ac78 | 2010-04-03 13:33:01 +0000 | [diff] [blame] | 134 | memset((void *)0xf0000, 0, 0x10000); |
Stefan Reinauer | 714e2a1 | 2010-04-24 23:15:23 +0000 | [diff] [blame] | 135 | #endif |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 138 | static const struct device_operations vga_operations = { |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 139 | .read_resources = pci_dev_read_resources, |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 140 | .set_resources = pci_dev_set_resources, |
| 141 | .enable_resources = pci_dev_enable_resources, |
| 142 | .init = vga_init, |
| 143 | .ops_pci = 0, |
| 144 | }; |
| 145 | |
| 146 | static const struct pci_driver vga_driver __pci_driver = { |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 147 | .ops = &vga_operations, |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 148 | .vendor = PCI_VENDOR_ID_VIA, |
| 149 | .device = PCI_DEVICE_ID_VIA_CN700_VGA, |
| 150 | }; |