blob: 74351bc3d03f3b6f8269a7f38ea5115f3f84d96e [file] [log] [blame]
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +00003 *
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
Alexandru Gagniuc025ead72011-02-16 13:43:00 +00005 * Copyright (C) 2011 Alexandru Gagniuc <mr.nuke.me@gmail.com>
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +00006 *
7 * This program is free software; you can redistribute it and/or modify
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000019 */
20
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ops.h>
24#include <device/pci_ids.h>
25#include <console/console.h>
Rudolf Marekbcaea142010-11-22 22:00:52 +000026#include <cbmem.h>
27#include <arch/io.h>
Alexandru Gagniuc025ead72011-02-16 13:43:00 +000028#include "k8x8xx.h"
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000029
Rudolf Marek316e07f2008-03-20 21:19:50 +000030/* this may be later merged */
31
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000032/* This fine tunes the HT link settings, which were loaded by ROM strap. */
Alexandru Gagniuc025ead72011-02-16 13:43:00 +000033static void host_ctrl_enable_k8t8xx(struct device *dev)
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000034{
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000035 /*
36 * Bit 4 is reserved but set by AW. Set PCI to HT outstanding
37 * requests to 3.
38 */
39 pci_write_config8(dev, 0xa0, 0x13);
40
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000041 /*
Rudolf Marek497c8ef2009-04-13 18:00:09 +000042 * NVRAM I/O base at K8T890_NVRAM_IO_BASE
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000043 * Some bits are set and reserved.
44 */
Rudolf Marek497c8ef2009-04-13 18:00:09 +000045 pci_write_config8(dev, 0xa2, (K8T890_NVRAM_IO_BASE >> 8));
46
47 /* enable NB NVRAM and enable non-posted PCI writes. */
48 pci_write_config8(dev, 0xa1, 0x8f);
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000049 /* Arbitration control, some bits are reserved. */
50 pci_write_config8(dev, 0xa5, 0x3c);
51
52 /* Arbitration control 2 */
53 pci_write_config8(dev, 0xa6, 0x80);
54
Rudolf Marek316e07f2008-03-20 21:19:50 +000055 /* this will be possibly removed, when I figure out
Stefan Reinauer14e22772010-04-27 06:56:47 +000056 * if the ROM SIP is good, second reason is that the
Rudolf Marek316e07f2008-03-20 21:19:50 +000057 * unknown bits are AGP related, which are dummy on K8T890
58 */
59
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000060 writeback(dev, 0xa0, 0x13); /* Bit4 is reserved! */
61 writeback(dev, 0xa1, 0x8e); /* Some bits are reserved. */
62 writeback(dev, 0xa2, 0x0e); /* I/O NVRAM base 0xe00-0xeff disabled. */
63 writeback(dev, 0xa3, 0x31);
64 writeback(dev, 0xa4, 0x30);
65
66 writeback(dev, 0xa5, 0x3c); /* Some bits reserved. */
67 writeback(dev, 0xa6, 0x80); /* Some bits reserved. */
68 writeback(dev, 0xa7, 0x86); /* Some bits reserved. */
69 writeback(dev, 0xa8, 0x7f); /* Some bits reserved. */
70 writeback(dev, 0xa9, 0xcf); /* Some bits reserved. */
71 writeback(dev, 0xaa, 0x44);
72 writeback(dev, 0xab, 0x22);
73 writeback(dev, 0xac, 0x35); /* Maybe bit0 is read-only? */
74
75 writeback(dev, 0xae, 0x22);
76 writeback(dev, 0xaf, 0x40);
77 /* b0 is missing. */
78 writeback(dev, 0xb1, 0x13);
79 writeback(dev, 0xb4, 0x02); /* Some bits are reserved. */
80 writeback(dev, 0xc0, 0x20);
81 writeback(dev, 0xc1, 0xaa);
82 writeback(dev, 0xc2, 0xaa);
83 writeback(dev, 0xc3, 0x02);
84 writeback(dev, 0xc4, 0x50);
85 writeback(dev, 0xc5, 0x50);
86
Alexandru Gagniuc025ead72011-02-16 13:43:00 +000087 print_debug(" VIA_X_2 device dump:\n");
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +000088 dump_south(dev);
89}
90
Rudolf Marek316e07f2008-03-20 21:19:50 +000091/* This fine tunes the HT link settings, which were loaded by ROM strap. */
Alexandru Gagniuc025ead72011-02-16 13:43:00 +000092static void host_ctrl_enable_k8m8xx(struct device *dev) {
Rudolf Marek316e07f2008-03-20 21:19:50 +000093
94 /*
95 * Set PCI to HT outstanding requests to 03.
96 * Bit 4 32 AGP ADS Read Outstanding Request Number
97 */
98 pci_write_config8(dev, 0xa0, 0x13);
99
Rudolf Marek316e07f2008-03-20 21:19:50 +0000100 /*
Rudolf Marek497c8ef2009-04-13 18:00:09 +0000101 * NVRAM I/O base at K8T890_NVRAM_IO_BASE
Rudolf Marek316e07f2008-03-20 21:19:50 +0000102 */
103
Rudolf Marek497c8ef2009-04-13 18:00:09 +0000104 pci_write_config8(dev, 0xa2, (K8T890_NVRAM_IO_BASE >> 8));
105
106 /* Enable NVRAM and enable non-posted PCI writes. */
107 pci_write_config8(dev, 0xa1, 0x8f);
108
Rudolf Marek316e07f2008-03-20 21:19:50 +0000109 /* Arbitration control */
110 pci_write_config8(dev, 0xa5, 0x3c);
111
Rudolf Marek0b0771d2008-09-19 22:58:59 +0000112 /* Arbitration control 2, Enable C2NOW delay to PSTATECTL */
113 pci_write_config8(dev, 0xa6, 0x83);
Rudolf Marek316e07f2008-03-20 21:19:50 +0000114
115}
Kyösti Mälkkibc90e152013-09-04 13:26:11 +0300116void backup_top_of_ram(uint64_t ramtop) {
117 outl((u32) ramtop, K8T890_NVRAM_IO_BASE+K8T890_NVRAM_TOP_OF_RAM);
Rudolf Marekbcaea142010-11-22 22:00:52 +0000118}
Rudolf Marek316e07f2008-03-20 21:19:50 +0000119
Rudolf Marek0f1dc4e2011-04-22 20:48:21 +0200120static struct pci_operations lops_pci = {
121 .set_subsystem = pci_dev_set_subsystem,
122};
123
Rudolf Marek316e07f2008-03-20 21:19:50 +0000124static const struct device_operations host_ctrl_ops_t = {
Uwe Hermann70ab3232007-11-15 15:52:42 +0000125 .read_resources = pci_dev_read_resources,
126 .set_resources = pci_dev_set_resources,
127 .enable_resources = pci_dev_enable_resources,
Alexandru Gagniuc025ead72011-02-16 13:43:00 +0000128 .enable = host_ctrl_enable_k8t8xx,
Rudolf Marek0f1dc4e2011-04-22 20:48:21 +0200129 .ops_pci = &lops_pci,
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +0000130};
131
Rudolf Marek316e07f2008-03-20 21:19:50 +0000132static const struct device_operations host_ctrl_ops_m = {
133 .read_resources = pci_dev_read_resources,
134 .set_resources = pci_dev_set_resources,
135 .enable_resources = pci_dev_enable_resources,
Alexandru Gagniuc025ead72011-02-16 13:43:00 +0000136 .enable = host_ctrl_enable_k8m8xx,
Rudolf Marek0f1dc4e2011-04-22 20:48:21 +0200137 .ops_pci = &lops_pci,
Rudolf Marek316e07f2008-03-20 21:19:50 +0000138};
139
Alexandru Gagniuc025ead72011-02-16 13:43:00 +0000140static const struct pci_driver northbridge_driver_t800 __pci_driver = {
141 .ops = &host_ctrl_ops_t,
142 .vendor = PCI_VENDOR_ID_VIA,
143 .device = PCI_DEVICE_ID_VIA_K8T800_HOST_CTR,
144};
145
146static const struct pci_driver northbridge_driver_m800 __pci_driver = {
147 .ops = &host_ctrl_ops_m,
148 .vendor = PCI_VENDOR_ID_VIA,
149 .device = PCI_DEVICE_ID_VIA_K8M800_HOST_CTR,
150};
151
152static const struct pci_driver northbridge_driver_t890 __pci_driver = {
Rudolf Marek316e07f2008-03-20 21:19:50 +0000153 .ops = &host_ctrl_ops_t,
Uwe Hermann70ab3232007-11-15 15:52:42 +0000154 .vendor = PCI_VENDOR_ID_VIA,
155 .device = PCI_DEVICE_ID_VIA_K8T890CE_2,
Rudolf Marek1d4fc0c2007-10-22 19:59:57 +0000156};
Rudolf Marek316e07f2008-03-20 21:19:50 +0000157
Alexandru Gagniuc025ead72011-02-16 13:43:00 +0000158static const struct pci_driver northbridge_driver_m890 __pci_driver = {
Rudolf Marek316e07f2008-03-20 21:19:50 +0000159 .ops = &host_ctrl_ops_m,
160 .vendor = PCI_VENDOR_ID_VIA,
161 .device = PCI_DEVICE_ID_VIA_K8M890CE_2,
162};