d6400d58590450abdfaa1ac63743e48faecede1a
[coreboot.git] / src / northbridge / intel / i3100 / pciexp_porta_ep80579.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 4DSP Inc
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 version 2 as
8  * published by the Free Software Foundation.
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
21 /* This code is based on src/northbridge/intel/i3100/pciexp_porta.c */
22
23 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <device/pci_ops.h>
28 #include <device/pciexp.h>
29 #include <arch/io.h>
30 #include "chip.h"
31 #include <reset.h>
32
33 typedef struct northbridge_intel_i3100_config config_t;
34
35 static void pcie_init(struct device *dev)
36 {
37         config_t *config;
38         u16 val;
39
40         /* Get the chip configuration */
41         config = dev->chip_info;
42
43         if(config->intrline) {
44                 pci_write_config32(dev, 0x3c, config->intrline);
45         }
46
47         printk(BIOS_SPEW, "configure PCIe port as \"Slot Implemented\"\n");
48         val = pci_read_config16(dev, 0x66);
49         val &= ~(1<<8);
50         val |= 1<<8;
51         pci_write_config16(dev, 0x66, val);
52
53         /* Todo configure the PCIe bootstrap mode (covered by Intel NDA) */
54 }
55
56
57 static void pcie_bus_enable_resources(struct device *dev)
58 {
59         if (dev->link[0].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
60                 printk(BIOS_SPEW, "Enable VGA IO/MEM forwarding on PCIe port\n");
61                 pci_write_config8(dev, PCI_BRIDGE_CONTROL, 8);
62                 
63                 dev->command |= PCI_COMMAND_IO;
64                 dev->command |= PCI_COMMAND_MEMORY;
65         }
66         pci_dev_enable_resources(dev);
67         enable_childrens_resources(dev);
68 }
69
70
71 static unsigned int pcie_scan_bridge(struct device *dev, unsigned int max)
72 {
73         u16 val;
74         u16 ctl;
75         int flag = 0;
76         do {
77                 val = pci_read_config16(dev, 0x76);
78                 printk(BIOS_DEBUG, "pcie porta 0x76: %02x\n", val);
79                 if ((val & (1<<11)) && (!flag)) { /* training error */
80                         ctl = pci_read_config16(dev, 0x74);
81                         pci_write_config16(dev, 0x74, (ctl | (1<<5)));
82                         val = pci_read_config16(dev, 0x76);
83                         printk(BIOS_DEBUG, "pcie porta reset 0x76: %02x\n", val);
84                         flag=1;
85                         hard_reset();
86                 }
87         } while (val & (3<<10));
88         return pciexp_scan_bridge(dev, max);
89 }
90
91 static struct device_operations pcie_ops  = {
92         .read_resources   = pci_bus_read_resources,
93         .set_resources    = pci_dev_set_resources,
94         .enable_resources = pcie_bus_enable_resources,
95         .init             = pcie_init,
96         .scan_bus         = pcie_scan_bridge,
97         .reset_bus        = pci_bus_reset,
98         .ops_pci          = 0,
99 };
100
101 static const struct pci_driver pci_driver_0 __pci_driver = {
102         .ops    = &pcie_ops,
103         .vendor = PCI_VENDOR_ID_INTEL,
104         .device = PCI_DEVICE_ID_INTEL_EP80579_PCIE_PA0,
105 };
106
107 static const struct pci_driver pci_driver_1 __pci_driver = {
108         .ops    = &pcie_ops,
109         .vendor = PCI_VENDOR_ID_INTEL,
110         .device = PCI_DEVICE_ID_INTEL_EP80579_PCIE_PA1,
111 };