blob: 2e453dc46328e5eeb953fa7638694ef585bedd02 [file] [log] [blame]
Corey Osgoodbd3f93e2008-02-21 00:56:14 +00001/*
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.
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000015 */
16
Uwe Hermannea7b5182008-10-09 17:08:32 +000017/*
18 * Note: Some of the VGA control registers are located on the memory
19 * controller. Registers are set both in raminit.c and northbridge.c.
20 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000021
22#include <console/console.h>
23#include <arch/io.h>
24#include <stdint.h>
25#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
28#include <stdlib.h>
29#include <string.h>
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000030#include <cpu/cpu.h>
Stefan Reinauer714e2a12010-04-24 23:15:23 +000031#include <arch/interrupt.h>
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000032#include "northbridge.h"
33#include "cn700.h"
Patrick Georgi199b09c2012-11-22 12:46:12 +010034#include <x86emu/regs.h>
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000035
Patrick Georgi199b09c2012-11-22 12:46:12 +010036static int via_cn700_int15_handler(void)
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000037{
Patrick Georgi503af722012-11-22 10:48:18 +010038 int res=0;
Stefan Reinauer714e2a12010-04-24 23:15:23 +000039 printk(BIOS_DEBUG, "via_cn700_int15_handler\n");
Patrick Georgi199b09c2012-11-22 12:46:12 +010040 switch(X86_EAX & 0xffff) {
Stefan Reinauer714e2a12010-04-24 23:15:23 +000041 case 0x5f19:
42 break;
43 case 0x5f18:
Patrick Georgi199b09c2012-11-22 12:46:12 +010044 X86_EAX=0x5f;
45 X86_EBX=0x545; // MCLK = 133, 32M frame buffer, 256 M main memory
46 X86_ECX=0x060;
Patrick Georgi503af722012-11-22 10:48:18 +010047 res=1;
Stefan Reinauer714e2a12010-04-24 23:15:23 +000048 break;
49 case 0x5f00:
Patrick Georgi199b09c2012-11-22 12:46:12 +010050 X86_EAX = 0x8600;
Stefan Reinauer714e2a12010-04-24 23:15:23 +000051 break;
52 case 0x5f01:
Patrick Georgi199b09c2012-11-22 12:46:12 +010053 X86_EAX = 0x5f;
54 X86_ECX = (X86_ECX & 0xffffff00 ) | 2; // panel type = 2 = 1024 * 768
Patrick Georgi503af722012-11-22 10:48:18 +010055 res = 1;
Stefan Reinauer714e2a12010-04-24 23:15:23 +000056 break;
57 case 0x5f02:
Patrick Georgi199b09c2012-11-22 12:46:12 +010058 X86_EAX=0x5f;
59 X86_EBX= (X86_EBX & 0xffff0000) | 2;
60 X86_ECX= (X86_ECX & 0xffff0000) | 0x401; // PAL + crt only
61 X86_EDX= (X86_EDX & 0xffff0000) | 0; // TV Layout - default
Patrick Georgi503af722012-11-22 10:48:18 +010062 res=1;
Stefan Reinauer714e2a12010-04-24 23:15:23 +000063 break;
64 case 0x5f0f:
Patrick Georgi199b09c2012-11-22 12:46:12 +010065 X86_EAX=0x860f;
Stefan Reinauer714e2a12010-04-24 23:15:23 +000066 break;
67 default:
Stefan Reinauer14e22772010-04-27 06:56:47 +000068 printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +010069 X86_EAX & 0xffff);
Stefan Reinauer714e2a12010-04-24 23:15:23 +000070 break;
71 }
72 return res;
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000073}
74
75static void vga_init(device_t dev)
76{
77 u8 reg8;
78
Stefan Reinauer714e2a12010-04-24 23:15:23 +000079 mainboard_interrupt_handlers(0x15, &via_cn700_int15_handler);
80
81#undef OLD_BOCHS_METHOD
82#ifdef OLD_BOCHS_METHOD
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080083 printk(BIOS_DEBUG, "Copying BOCHS BIOS to 0xf000\n");
Uwe Hermannea7b5182008-10-09 17:08:32 +000084 /*
Stefan Reinauer08670622009-06-30 15:17:49 +000085 * Copy BOCHS BIOS from 4G-CONFIG_ROM_SIZE-64k (in flash) to 0xf0000 (in RAM)
Uwe Hermannea7b5182008-10-09 17:08:32 +000086 * This is for compatibility with the VGA ROM's BIOS callbacks.
87 */
Stefan Reinauer3c8ac782010-04-03 13:33:01 +000088 memcpy((void *)0xf0000, (const void *)(0xffffffff - CONFIG_ROM_SIZE - 0xffff), 0x10000);
Stefan Reinauer714e2a12010-04-24 23:15:23 +000089#endif
Uwe Hermannea7b5182008-10-09 17:08:32 +000090
91 /* Set memory rate to 200 MHz. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000092 outb(0x3d, CRTM_INDEX);
93 reg8 = inb(CRTM_DATA);
94 reg8 &= 0x0f;
95 reg8 |= (0x1 << 4);
96 outb(0x3d, CRTM_INDEX);
97 outb(reg8, CRTM_DATA);
Uwe Hermannea7b5182008-10-09 17:08:32 +000098
99 /* Set framebuffer size. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000100 reg8 = (CONFIG_VIDEO_MB / 4);
101 outb(0x39, SR_INDEX);
102 outb(reg8, SR_DATA);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000103
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000104 pci_write_config8(dev, 0x04, 0x07);
105 pci_write_config8(dev, 0x0d, 0x20);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000106 pci_write_config32(dev, 0x10, 0xf4000008);
107 pci_write_config32(dev, 0x14, 0xfb000000);
108
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000109 printk(BIOS_DEBUG, "Initializing VGA...\n");
110
111 pci_dev_init(dev);
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000112
113 /* It's not clear if these need to be programmed before or after
Uwe Hermannea7b5182008-10-09 17:08:32 +0000114 * the VGA BIOS runs. Try both, clean up later. */
115 /* Set memory rate to 200 MHz (again). */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000116 outb(0x3d, CRTM_INDEX);
117 reg8 = inb(CRTM_DATA);
118 reg8 &= 0x0f;
119 reg8 |= (0x1 << 4);
120 outb(0x3d, CRTM_INDEX);
121 outb(reg8, CRTM_DATA);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000122
123 /* Set framebuffer size (again). */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000124 reg8 = (CONFIG_VIDEO_MB / 4);
125 outb(0x39, SR_INDEX);
126 outb(reg8, SR_DATA);
127
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000128#ifdef OLD_BOCHS_METHOD
Uwe Hermannea7b5182008-10-09 17:08:32 +0000129 /* Clear the BOCHS BIOS out of memory, so it doesn't confuse Linux. */
Stefan Reinauer3c8ac782010-04-03 13:33:01 +0000130 memset((void *)0xf0000, 0, 0x10000);
Stefan Reinauer714e2a12010-04-24 23:15:23 +0000131#endif
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000132}
133
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000134static const struct device_operations vga_operations = {
Myles Watsond27c08c2009-11-06 23:42:26 +0000135 .read_resources = pci_dev_read_resources,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000136 .set_resources = pci_dev_set_resources,
137 .enable_resources = pci_dev_enable_resources,
138 .init = vga_init,
139 .ops_pci = 0,
140};
141
142static const struct pci_driver vga_driver __pci_driver = {
Uwe Hermannea7b5182008-10-09 17:08:32 +0000143 .ops = &vga_operations,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000144 .vendor = PCI_VENDOR_ID_VIA,
145 .device = PCI_DEVICE_ID_VIA_CN700_VGA,
146};