summaryrefslogtreecommitdiff
path: root/src/southbridge/via/k8t890/k8t890_pcie.c
blob: 21acf167805f97a29dfeaca6350af3a527a466f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * This file is part of the LinuxBIOS project.
 *
 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License v2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include <console/console.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pciexp.h>
#include <device/pci_ops.h>
#include <device/pci_ids.h>

void peg_init(struct device *dev)
{
	u8 reg;

	printk_debug("Configuring PCIe PEG\n");
	dump_south(dev);

	/* Disable link. */
	reg = pci_read_config8(dev, 0x50);
	pci_write_config8(dev, 0x50, reg | 0x10);

	/* Award has 0xb, VIA recomends 0x4. */
	pci_write_config8(dev, 0xe1, 0xb);

	/*
	 * pci_write_config8(dev, 0xe2, 0x0);
	 * pci_write_config8(dev, 0xe3, 0x92);
	 */
	/* Disable scrambling bit 6 to 1. */
	pci_write_config8(dev, 0xc0, 0x43);

	/* Set replay timer limit. */
	pci_write_config8(dev, 0xb1, 0xf0);

	/* Bit0 = 1 SDP (Start DLLP) always at Lane0. */
	reg = pci_read_config8(dev, 0xb8);
	pci_write_config8(dev, 0xb8, reg | 0x1);

	/*
	 * Downstream wait and Upstream Checking Malformed TLP through
	 * "Byte Enable Rule" And "Over 4K Boundary Rule".
	 */
	reg = pci_read_config8(dev, 0xa4);
	pci_write_config8(dev, 0xa4, reg | 0x30);

	/* Enable link. */
	reg = pci_read_config8(dev, 0x50);
	pci_write_config8(dev, 0x50, reg & ~0x10);

	/* Retrain link. */
	reg = pci_read_config8(dev, 0x50);
	pci_write_config8(dev, 0x50, reg | 0x20);

	reg = pci_read_config8(dev, 0x3e);
	reg |= 0x40;		/* Bus reset. */
	pci_write_config8(dev, 0x3e, reg);

	reg = pci_read_config8(dev, 0x3e);
	reg &= ~0x40;		/* Clear reset. */
	pci_write_config8(dev, 0x3e, reg);

	dump_south(dev);
}

void pcie_init(struct device *dev)
{
	u8 reg;

	printk_debug("Configuring PCIe PEXs\n");
	dump_south(dev);

	/* Disable link. */
	reg = pci_read_config8(dev, 0x50);
	pci_write_config8(dev, 0x50, reg | 0x10);

	/* Award has 0xb, VIA recommends 0x4. */
	pci_write_config8(dev, 0xe1, 0xb);
	/* Set replay timer limit. */
	pci_write_config8(dev, 0xb1, 0xf0);

	/* Enable link. */
	reg = pci_read_config8(dev, 0x50);
	pci_write_config8(dev, 0x50, reg & ~0x10);

	/* Retrain. */
	reg = pci_read_config8(dev, 0x50);
	pci_write_config8(dev, 0x50, reg | 0x20);

	reg = pci_read_config8(dev, 0x3e);
	reg |= 0x40;		/* Bus reset. */
	pci_write_config8(dev, 0x3e, reg);

	reg = pci_read_config8(dev, 0x3e);
	reg &= ~0x40;		/* Clear reset. */
	pci_write_config8(dev, 0x3e, reg);

	dump_south(dev);
}

static struct device_operations peg_ops = {
	.read_resources = pci_bus_read_resources,
	.set_resources = pci_dev_set_resources,
	.enable_resources = pci_bus_enable_resources,
	.enable = peg_init,
	.scan_bus = pciexp_scan_bridge,
	.reset_bus = pci_bus_reset,
	.ops_pci = 0,
};

static struct device_operations pcie_ops = {
	.read_resources = pci_bus_read_resources,
	.set_resources = pci_dev_set_resources,
	.enable_resources = pci_bus_enable_resources,
	.enable = pcie_init,
	.scan_bus = pciexp_scan_bridge,
	.reset_bus = pci_bus_reset,
	.ops_pci = 0,
};

static const struct pci_driver northbridge_driver __pci_driver = {
	.ops = &peg_ops,
	.vendor = PCI_VENDOR_ID_VIA,
	.device = PCI_DEVICE_ID_VIA_K8T890CE_PEG,
};

static const struct pci_driver pcie_drvd3f0 __pci_driver = {
	.ops = &pcie_ops,
	.vendor = PCI_VENDOR_ID_VIA,
	.device = PCI_DEVICE_ID_VIA_K8T890CE_PEX0,
};

static const struct pci_driver pcie_drvd3f1 __pci_driver = {
	.ops = &pcie_ops,
	.vendor = PCI_VENDOR_ID_VIA,
	.device = PCI_DEVICE_ID_VIA_K8T890CE_PEX1,
};

static const struct pci_driver pcie_drvd3f2 __pci_driver = {
	.ops = &pcie_ops,
	.vendor = PCI_VENDOR_ID_VIA,
	.device = PCI_DEVICE_ID_VIA_K8T890CE_PEX2,
};

static const struct pci_driver pcie_drvd3f3 __pci_driver = {
	.ops = &pcie_ops,
	.vendor = PCI_VENDOR_ID_VIA,
	.device = PCI_DEVICE_ID_VIA_K8T890CE_PEX3,
};