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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 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> |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 26 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 27 | #define GDRST 0xc0 |
| 28 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 29 | static void gma_func0_init(struct device *dev) |
| 30 | { |
| 31 | u32 reg32; |
| 32 | |
Patrick Georgi | 6444bd4 | 2012-07-06 11:31:39 +0200 | [diff] [blame] | 33 | /* Unconditionally reset graphics */ |
| 34 | pci_write_config8(dev, GDRST, 1); |
| 35 | udelay(50); |
| 36 | pci_write_config8(dev, GDRST, 0); |
| 37 | /* wait for device to finish */ |
| 38 | while (pci_read_config8(dev, GDRST) & 1) { }; |
| 39 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 40 | /* IGD needs to be Bus Master */ |
| 41 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 42 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_MASTER); |
| 43 | |
| 44 | pci_dev_init(dev); |
| 45 | } |
| 46 | |
| 47 | static void gma_func1_init(struct device *dev) |
| 48 | { |
| 49 | u32 reg32; |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 50 | u8 val; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 51 | |
| 52 | /* IGD needs to be Bus Master, also enable IO accesss */ |
| 53 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 54 | pci_write_config32(dev, PCI_COMMAND, reg32 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 55 | PCI_COMMAND_MASTER | PCI_COMMAND_IO); |
Sven Schnelle | b629d14 | 2011-06-12 14:30:10 +0200 | [diff] [blame] | 56 | |
| 57 | if (!get_option(&val, "tft_brightness")) |
| 58 | pci_write_config8(dev, 0xf4, val); |
| 59 | else |
| 60 | pci_write_config8(dev, 0xf4, 0xff); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 64 | { |
| 65 | if (!vendor || !device) { |
| 66 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 67 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 68 | } else { |
| 69 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 70 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | static struct pci_operations gma_pci_ops = { |
| 75 | .set_subsystem = gma_set_subsystem, |
| 76 | }; |
| 77 | |
| 78 | static struct device_operations gma_func0_ops = { |
| 79 | .read_resources = pci_dev_read_resources, |
| 80 | .set_resources = pci_dev_set_resources, |
| 81 | .enable_resources = pci_dev_enable_resources, |
| 82 | .init = gma_func0_init, |
| 83 | .scan_bus = 0, |
| 84 | .enable = 0, |
| 85 | .ops_pci = &gma_pci_ops, |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | static struct device_operations gma_func1_ops = { |
| 90 | .read_resources = pci_dev_read_resources, |
| 91 | .set_resources = pci_dev_set_resources, |
| 92 | .enable_resources = pci_dev_enable_resources, |
| 93 | .init = gma_func1_init, |
| 94 | .scan_bus = 0, |
| 95 | .enable = 0, |
| 96 | .ops_pci = &gma_pci_ops, |
| 97 | }; |
| 98 | |
| 99 | static const struct pci_driver i945_gma_func0_driver __pci_driver = { |
| 100 | .ops = &gma_func0_ops, |
| 101 | .vendor = PCI_VENDOR_ID_INTEL, |
| 102 | .device = 0x27a2, |
| 103 | }; |
| 104 | |
| 105 | static const struct pci_driver i945_gma_func1_driver __pci_driver = { |
| 106 | .ops = &gma_func1_ops, |
| 107 | .vendor = PCI_VENDOR_ID_INTEL, |
| 108 | .device = 0x27a6, |
| 109 | }; |
| 110 | |