Please bear with me - another rename checkin. This qualifies as trivial, no
[coreboot.git] / src / southbridge / via / k8t890 / k8t890_pcie.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
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 v2 as published by
8  * 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 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pciexp.h>
24 #include <device/pci_ids.h>
25
26 static void peg_init(struct device *dev)
27 {
28         u8 reg;
29
30         printk_debug("Configuring PCIe PEG\n");
31         dump_south(dev);
32
33         /* Disable link. */
34         reg = pci_read_config8(dev, 0x50);
35         pci_write_config8(dev, 0x50, reg | 0x10);
36
37         /* Award has 0xb, VIA recomends 0x4. */
38         pci_write_config8(dev, 0xe1, 0xb);
39
40         /*
41          * pci_write_config8(dev, 0xe2, 0x0);
42          * pci_write_config8(dev, 0xe3, 0x92);
43          */
44         /* Disable scrambling bit 6 to 1. */
45         pci_write_config8(dev, 0xc0, 0x43);
46
47         /* Set replay timer limit. */
48         pci_write_config8(dev, 0xb1, 0xf0);
49
50         /* Bit0 = 1 SDP (Start DLLP) always at Lane0. */
51         reg = pci_read_config8(dev, 0xb8);
52         pci_write_config8(dev, 0xb8, reg | 0x1);
53
54         /*
55          * Downstream wait and Upstream Checking Malformed TLP through
56          * "Byte Enable Rule" And "Over 4K Boundary Rule".
57          */
58         reg = pci_read_config8(dev, 0xa4);
59         pci_write_config8(dev, 0xa4, reg | 0x30);
60
61         /* Enable link. */
62         reg = pci_read_config8(dev, 0x50);
63         pci_write_config8(dev, 0x50, reg & ~0x10);
64
65         /* Retrain link. */
66         reg = pci_read_config8(dev, 0x50);
67         pci_write_config8(dev, 0x50, reg | 0x20);
68
69         reg = pci_read_config8(dev, 0x3e);
70         reg |= 0x40;            /* Bus reset. */
71         pci_write_config8(dev, 0x3e, reg);
72
73         reg = pci_read_config8(dev, 0x3e);
74         reg &= ~0x40;           /* Clear reset. */
75         pci_write_config8(dev, 0x3e, reg);
76
77         dump_south(dev);
78 }
79
80 static void pcie_init(struct device *dev)
81 {
82         u8 reg;
83
84         printk_debug("Configuring PCIe PEXs\n");
85         dump_south(dev);
86
87         /* Disable link. */
88         reg = pci_read_config8(dev, 0x50);
89         pci_write_config8(dev, 0x50, reg | 0x10);
90
91         /* Award has 0xb, VIA recommends 0x4. */
92         pci_write_config8(dev, 0xe1, 0xb);
93         /* Set replay timer limit. */
94         pci_write_config8(dev, 0xb1, 0xf0);
95
96         /* Enable link. */
97         reg = pci_read_config8(dev, 0x50);
98         pci_write_config8(dev, 0x50, reg & ~0x10);
99
100         /* Retrain. */
101         reg = pci_read_config8(dev, 0x50);
102         pci_write_config8(dev, 0x50, reg | 0x20);
103
104         reg = pci_read_config8(dev, 0x3e);
105         reg |= 0x40;            /* Bus reset. */
106         pci_write_config8(dev, 0x3e, reg);
107
108         reg = pci_read_config8(dev, 0x3e);
109         reg &= ~0x40;           /* Clear reset. */
110         pci_write_config8(dev, 0x3e, reg);
111
112         dump_south(dev);
113 }
114
115 static const struct device_operations peg_ops = {
116         .read_resources         = pci_bus_read_resources,
117         .set_resources          = pci_dev_set_resources,
118         .enable_resources       = pci_bus_enable_resources,
119         .enable                 = peg_init,
120         .scan_bus               = pciexp_scan_bridge,
121         .reset_bus              = pci_bus_reset,
122         .ops_pci                = 0,
123 };
124
125 static const struct device_operations pcie_ops = {
126         .read_resources         = pci_bus_read_resources,
127         .set_resources          = pci_dev_set_resources,
128         .enable_resources       = pci_bus_enable_resources,
129         .enable                 = pcie_init,
130         .scan_bus               = pciexp_scan_bridge,
131         .reset_bus              = pci_bus_reset,
132         .ops_pci                = 0,
133 };
134
135 static const struct pci_driver northbridge_driver __pci_driver = {
136         .ops    = &peg_ops,
137         .vendor = PCI_VENDOR_ID_VIA,
138         .device = PCI_DEVICE_ID_VIA_K8T890CE_PEG,
139 };
140
141 static const struct pci_driver pcie_drvd3f0 __pci_driver = {
142         .ops    = &pcie_ops,
143         .vendor = PCI_VENDOR_ID_VIA,
144         .device = PCI_DEVICE_ID_VIA_K8T890CE_PEX0,
145 };
146
147 static const struct pci_driver pcie_drvd3f1 __pci_driver = {
148         .ops    = &pcie_ops,
149         .vendor = PCI_VENDOR_ID_VIA,
150         .device = PCI_DEVICE_ID_VIA_K8T890CE_PEX1,
151 };
152
153 static const struct pci_driver pcie_drvd3f2 __pci_driver = {
154         .ops    = &pcie_ops,
155         .vendor = PCI_VENDOR_ID_VIA,
156         .device = PCI_DEVICE_ID_VIA_K8T890CE_PEX2,
157 };
158
159 static const struct pci_driver pcie_drvd3f3 __pci_driver = {
160         .ops    = &pcie_ops,
161         .vendor = PCI_VENDOR_ID_VIA,
162         .device = PCI_DEVICE_ID_VIA_K8T890CE_PEX3,
163 };