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> |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 21 | #include <bootmode.h> |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 22 | #include <delay.h> |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 26 | #include <pc80/mc146818rtc.h> |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 27 | #include "i945.h" |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 28 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 29 | #define GDRST 0xc0 |
| 30 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 31 | static void gma_func0_init(struct device *dev) |
| 32 | { |
| 33 | u32 reg32; |
| 34 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 35 | /* Unconditionally reset graphics */ |
| 36 | pci_write_config8(dev, GDRST, 1); |
| 37 | udelay(50); |
| 38 | pci_write_config8(dev, GDRST, 0); |
| 39 | /* wait for device to finish */ |
| 40 | while (pci_read_config8(dev, GDRST) & 1) { }; |
| 41 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 42 | /* IGD needs to be Bus Master */ |
| 43 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 44 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 45 | |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 46 | |
| 47 | #if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 48 | /* PCI Init, will run VBIOS */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 49 | pci_dev_init(dev); |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 50 | #endif |
| 51 | |
| 52 | |
| 53 | #if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 54 | /* This should probably run before post VBIOS init. */ |
| 55 | printk(BIOS_SPEW, "Initializing VGA without OPROM.\n"); |
Peter Stuge | 03e4ac6 | 2013-06-08 01:25:43 +0200 | [diff] [blame] | 56 | u32 iobase, mmiobase, graphics_base; |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 57 | iobase = dev->resource_list[1].base; |
| 58 | mmiobase = dev->resource_list[0].base; |
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 | |
Peter Stuge | c6f0997 | 2013-06-08 01:31:44 +0200 | [diff] [blame] | 61 | printk(BIOS_SPEW, "GMADR=0x%08x GTTADR=0x%08x\n", |
| 62 | pci_read_config32(dev, 0x18), |
| 63 | pci_read_config32(dev, 0x1c) |
| 64 | ); |
| 65 | |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 66 | int i915lightup(u32 physbase, u32 iobase, u32 mmiobase, u32 gfx); |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 67 | int lightup_ok = i915lightup(uma_memory_base, iobase, mmiobase, graphics_base); |
| 68 | if (lightup_ok) |
| 69 | gfx_set_init_done(1); |
Denis 'GNUtoo' Carikli | ed7e29e | 2013-02-24 12:01:44 +0100 | [diff] [blame] | 70 | #endif |
| 71 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 74 | /* This doesn't reclaim stolen UMA memory, but IGD could still |
| 75 | be reenabled later. */ |
| 76 | static void gma_func0_disable(struct device *dev) |
| 77 | { |
| 78 | struct device *dev_host = dev_find_slot(0, PCI_DEVFN(0x0, 0)); |
| 79 | |
| 80 | pci_write_config16(dev, GCFC, 0xa00); |
| 81 | pci_write_config16(dev_host, GGC, (1 << 1)); |
| 82 | |
| 83 | unsigned int reg32 = pci_read_config32(dev_host, DEVEN); |
| 84 | reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1); |
| 85 | pci_write_config32(dev_host, DEVEN, reg32); |
| 86 | |
| 87 | dev->enabled = 0; |
| 88 | } |
| 89 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 90 | static void gma_func1_init(struct device *dev) |
| 91 | { |
| 92 | u32 reg32; |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 93 | u8 val; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 94 | |
| 95 | /* IGD needs to be Bus Master, also enable IO accesss */ |
| 96 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 97 | pci_write_config32(dev, PCI_COMMAND, reg32 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 98 | PCI_COMMAND_MASTER | PCI_COMMAND_IO); |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 99 | |
Alexandru Gagniuc | 72dccce | 2013-11-23 19:22:53 -0600 | [diff] [blame] | 100 | if (get_option(&val, "tft_brightness") == CB_SUCCESS) |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 101 | pci_write_config8(dev, 0xf4, val); |
| 102 | else |
| 103 | pci_write_config8(dev, 0xf4, 0xff); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 107 | { |
| 108 | if (!vendor || !device) { |
| 109 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 110 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 111 | } else { |
| 112 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 113 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | static struct pci_operations gma_pci_ops = { |
| 118 | .set_subsystem = gma_set_subsystem, |
| 119 | }; |
| 120 | |
| 121 | static struct device_operations gma_func0_ops = { |
| 122 | .read_resources = pci_dev_read_resources, |
| 123 | .set_resources = pci_dev_set_resources, |
| 124 | .enable_resources = pci_dev_enable_resources, |
| 125 | .init = gma_func0_init, |
| 126 | .scan_bus = 0, |
| 127 | .enable = 0, |
Patrick Georgi | ce6e9fe | 2012-07-20 12:37:06 +0200 | [diff] [blame] | 128 | .disable = gma_func0_disable, |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 129 | .ops_pci = &gma_pci_ops, |
| 130 | }; |
| 131 | |
| 132 | |
| 133 | static struct device_operations gma_func1_ops = { |
| 134 | .read_resources = pci_dev_read_resources, |
| 135 | .set_resources = pci_dev_set_resources, |
| 136 | .enable_resources = pci_dev_enable_resources, |
| 137 | .init = gma_func1_init, |
| 138 | .scan_bus = 0, |
| 139 | .enable = 0, |
| 140 | .ops_pci = &gma_pci_ops, |
| 141 | }; |
| 142 | |
| 143 | static const struct pci_driver i945_gma_func0_driver __pci_driver = { |
| 144 | .ops = &gma_func0_ops, |
| 145 | .vendor = PCI_VENDOR_ID_INTEL, |
| 146 | .device = 0x27a2, |
| 147 | }; |
| 148 | |
| 149 | static const struct pci_driver i945_gma_func1_driver __pci_driver = { |
| 150 | .ops = &gma_func1_ops, |
| 151 | .vendor = PCI_VENDOR_ID_INTEL, |
| 152 | .device = 0x27a6, |
| 153 | }; |
| 154 | |