Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 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; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <console/console.h> |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 21 | #include <delay.h> |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 25 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 26 | #include "i945.h" |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 27 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 28 | #define GDRST 0xc0 |
| 29 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 30 | static void gma_func0_init(struct device *dev) |
| 31 | { |
| 32 | u32 reg32; |
| 33 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 34 | /* Unconditionally reset graphics */ |
| 35 | pci_write_config8(dev, GDRST, 1); |
| 36 | udelay(50); |
| 37 | pci_write_config8(dev, GDRST, 0); |
| 38 | /* wait for device to finish */ |
| 39 | while (pci_read_config8(dev, GDRST) & 1) { }; |
| 40 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 41 | /* IGD needs to be Bus Master */ |
| 42 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 43 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 44 | |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 45 | |
| 46 | #if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 47 | /* PCI Init, will run VBIOS */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 48 | pci_dev_init(dev); |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 49 | #endif |
| 50 | |
| 51 | |
| 52 | #if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 53 | /* This should probably run before post VBIOS init. */ |
| 54 | printk(BIOS_SPEW, "Initializing VGA without OPROM.\n"); |
| 55 | u32 iobase, mmiobase, physbase, graphics_base; |
| 56 | iobase = dev->resource_list[1].base; |
| 57 | mmiobase = dev->resource_list[0].base; |
| 58 | physbase = pci_read_config32(dev, 0x5c) & ~0xf; |
Denis 'GNUtoo' Carikli | 2186b65 | 2013-10-27 15:50:02 +0100 | [diff] [blame] | 59 | graphics_base = dev->resource_list[2].base + 0x20000; |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 60 | |
| 61 | int i915lightup(u32 physbase, u32 iobase, u32 mmiobase, u32 gfx); |
| 62 | i915lightup(physbase, iobase, mmiobase, graphics_base); |
| 63 | #endif |
| 64 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 67 | /* This doesn't reclaim stolen UMA memory, but IGD could still |
| 68 | be reenabled later. */ |
| 69 | static void gma_func0_disable(struct device *dev) |
| 70 | { |
| 71 | struct device *dev_host = dev_find_slot(0, PCI_DEVFN(0x0, 0)); |
| 72 | |
| 73 | pci_write_config16(dev, GCFC, 0xa00); |
| 74 | pci_write_config16(dev_host, GGC, (1 << 1)); |
| 75 | |
| 76 | unsigned int reg32 = pci_read_config32(dev_host, DEVEN); |
| 77 | reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1); |
| 78 | pci_write_config32(dev_host, DEVEN, reg32); |
| 79 | |
| 80 | dev->enabled = 0; |
| 81 | } |
| 82 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 83 | static void gma_func1_init(struct device *dev) |
| 84 | { |
| 85 | u32 reg32; |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 86 | u8 val; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 87 | |
| 88 | /* IGD needs to be Bus Master, also enable IO accesss */ |
| 89 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 90 | pci_write_config32(dev, PCI_COMMAND, reg32 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 91 | PCI_COMMAND_MASTER | PCI_COMMAND_IO); |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 92 | |
| 93 | if (!get_option(&val, "tft_brightness")) |
| 94 | pci_write_config8(dev, 0xf4, val); |
| 95 | else |
| 96 | pci_write_config8(dev, 0xf4, 0xff); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 100 | { |
| 101 | if (!vendor || !device) { |
| 102 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 103 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 104 | } else { |
| 105 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 106 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | static struct pci_operations gma_pci_ops = { |
| 111 | .set_subsystem = gma_set_subsystem, |
| 112 | }; |
| 113 | |
| 114 | static struct device_operations gma_func0_ops = { |
| 115 | .read_resources = pci_dev_read_resources, |
| 116 | .set_resources = pci_dev_set_resources, |
| 117 | .enable_resources = pci_dev_enable_resources, |
| 118 | .init = gma_func0_init, |
| 119 | .scan_bus = 0, |
| 120 | .enable = 0, |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 121 | .disable = gma_func0_disable, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 122 | .ops_pci = &gma_pci_ops, |
| 123 | }; |
| 124 | |
| 125 | |
| 126 | static struct device_operations gma_func1_ops = { |
| 127 | .read_resources = pci_dev_read_resources, |
| 128 | .set_resources = pci_dev_set_resources, |
| 129 | .enable_resources = pci_dev_enable_resources, |
| 130 | .init = gma_func1_init, |
| 131 | .scan_bus = 0, |
| 132 | .enable = 0, |
| 133 | .ops_pci = &gma_pci_ops, |
| 134 | }; |
| 135 | |
| 136 | static const struct pci_driver i945_gma_func0_driver __pci_driver = { |
| 137 | .ops = &gma_func0_ops, |
| 138 | .vendor = PCI_VENDOR_ID_INTEL, |
| 139 | .device = 0x27a2, |
| 140 | }; |
| 141 | |
| 142 | static const struct pci_driver i945_gma_func1_driver __pci_driver = { |
| 143 | .ops = &gma_func1_ops, |
| 144 | .vendor = PCI_VENDOR_ID_INTEL, |
| 145 | .device = 0x27a6, |
| 146 | }; |
| 147 | |