Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / northbridge / via / cn400 / vga.c
index 0624ba1e3fc25e2bc53a8a20e8ade0fe79335019..511079b03a48633cda95ba0896f7639ecaff1c49 100644 (file)
 #include <string.h>
 #include <bitops.h>
 #include <cpu/cpu.h>
+#include <arch/interrupt.h>
 #include "chip.h"
 #include "northbridge.h"
 #include "cn400.h"
-#include "vgachip.h"
 
-void write_protect_vgabios(void)
+static int via_cn400_int15_handler(struct eregs *regs)
 {
-       /* Don't bother for now. */
+       int res=-1;
+       printk(BIOS_DEBUG, "via_cn400_int15_handler\n");
+       switch(regs->eax & 0xffff) {
+       case 0x5f19:
+               break;
+       case 0x5f18:
+               regs->eax=0x5f;
+               regs->ebx=0x545; // MCLK = 133, 32M frame buffer, 256 M main memory
+               regs->ecx=0x060;
+               res=0;
+               break;
+       case 0x5f00:
+               regs->eax = 0x8600;
+               break;
+       case 0x5f01:
+               regs->eax = 0x5f;
+               regs->ecx = (regs->ecx & 0xffffff00 ) | 2; // panel type =  2 = 1024 * 768
+               res = 0;
+               break;
+       case 0x5f02:
+               regs->eax=0x5f;
+               regs->ebx= (regs->ebx & 0xffff0000) | 2;
+               regs->ecx= (regs->ecx & 0xffff0000) | 0x401;  // PAL + crt only
+               regs->edx= (regs->edx & 0xffff0000) | 0;  // TV Layout - default
+               res=0;
+               break;
+       case 0x5f0f:
+               regs->eax=0x860f;
+               break;
+        default:
+               printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n",
+                               regs->eax & 0xffff);
+               break;
+       }
+       return res;
 }
 
 static void vga_init(device_t dev)
 {
        u8 reg8;
-       u32 temp;
 
+       mainboard_interrupt_handlers(0x15, &via_cn400_int15_handler);
+
+#undef OLD_BOCHS_METHOD
+#ifdef OLD_BOCHS_METHOD
+       u32 temp;
+       // XXX We might need more bios hooks in the f segment, but
+       // this way of copying the BOCHS BIOS does not work anymore.
+       // As soon as someone verifies that CN400 can init VGA, the
+       // code should be removed.
        temp = (0xffffffff - CONFIG_FALLBACK_SIZE - 0xffff);
-       printk_debug("Copying BOCHS BIOS from 0x%08X    to 0xf000\n", temp);
+       printk(BIOS_DEBUG, "Copying BOCHS BIOS from 0x%08X      to 0xf000\n", temp);
        /*
         * Copy BOCHS BIOS from 4G-CONFIG_FALLBACK_SIZE-64k (in flash) to 0xf0000 (in RAM)
         * This is for compatibility with the VGA ROM's BIOS callbacks.
         */
        //memcpy(0xf0000, (0xffffffff - CONFIG_ROM_SIZE - 0xffff), 0x10000);
-       memcpy(0xf0000, temp, 0x10000);
-       printk_debug("Initializing VGA\n");
+       memcpy((void *)0xf0000, (void *)temp, 0x10000);
+#endif
 
        /* Set memory rate to 200 MHz. */
        outb(0x3d, CRTM_INDEX);
@@ -73,19 +115,16 @@ static void vga_init(device_t dev)
 
        pci_write_config8(dev, 0x04, 0x07);
        pci_write_config8(dev, 0x0d, 0x20);
-       pci_write_config32(dev, 0x10, 0xf4000008);
-       pci_write_config32(dev, 0x14, 0xfb000000);
+       pci_write_config32(dev, 0x10, 0xf0000008);
+       pci_write_config32(dev, 0x14, 0xf4000000);
 
-       printk_debug("INSTALL REAL-MODE IDT\n");
-       setup_realmode_idt();
-       printk_debug("DO THE VGA BIOS\n");
-       do_vgabios();
-       /* VGA seems to work without this, but crash & burn with it. */
-       // printk_debug("Enable VGA console\n");
-       // vga_enable_console();
+       printk(BIOS_DEBUG, "Initializing VGA...\n");
+
+       pci_dev_init(dev);
 
        /* It's not clear if these need to be programmed before or after
         * the VGA BIOS runs. Try both, clean up later. */
+
        /* Set memory rate to 200 MHz (again). */
        outb(0x3d, CRTM_INDEX);
        reg8 = inb(CRTM_DATA);
@@ -99,19 +138,31 @@ static void vga_init(device_t dev)
        outb(0x39, SR_INDEX);
        outb(reg8, SR_DATA);
 
+#ifdef OLD_BOCHS_METHOD
        /* Clear the BOCHS BIOS out of memory, so it doesn't confuse Linux. */
-       memset(0xf0000, 0, 0x10000);
-}
+       memset((void *)0xf0000, 0, 0x10000);
+#endif
 
-static void vga_read_resources(device_t dev)
-{
-       dev->rom_address = 0xfff80000;
-       dev->on_mainboard = 1;
-       pci_dev_read_resources(dev);
+#ifdef DEBUG_CN400
+       int i, j;
+
+       printk(BIOS_SPEW, "%s PCI Header Regs::\n", dev_path(dev));
+
+       for (i = 0 ; i < 16; i++)
+       {
+               printk(BIOS_SPEW, "%02X: ", i*16);
+               for (j = 0; j < 16; j++)
+               {
+                       reg8 = pci_read_config8(dev, j+(i*16));
+                       printk(BIOS_SPEW, "%02X ", reg8);
+               }
+               printk(BIOS_SPEW, "\n");
+       }
+#endif
 }
 
 static const struct device_operations vga_operations = {
-       .read_resources   = vga_read_resources,
+       .read_resources   = pci_dev_read_resources,
        .set_resources    = pci_dev_set_resources,
        .enable_resources = pci_dev_enable_resources,
        .init             = vga_init,