Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz> |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 5 | * Copyright (C) 2011 Alexandru Gagniuc <mr.nuke.me@gmail.com> |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 10 | * |
| 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 Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 19 | */ |
| 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 Marek | bcaea14 | 2010-11-22 22:00:52 +0000 | [diff] [blame] | 26 | #include <cbmem.h> |
| 27 | #include <arch/io.h> |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 28 | #include "k8x8xx.h" |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 29 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 30 | /* this may be later merged */ |
| 31 | |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 32 | /* This fine tunes the HT link settings, which were loaded by ROM strap. */ |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 33 | static void host_ctrl_enable_k8t8xx(struct device *dev) |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 34 | { |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 35 | /* |
| 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 Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 41 | /* |
Rudolf Marek | 497c8ef | 2009-04-13 18:00:09 +0000 | [diff] [blame] | 42 | * NVRAM I/O base at K8T890_NVRAM_IO_BASE |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 43 | * Some bits are set and reserved. |
| 44 | */ |
Rudolf Marek | 497c8ef | 2009-04-13 18:00:09 +0000 | [diff] [blame] | 45 | 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 Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 49 | /* 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 Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 55 | /* this will be possibly removed, when I figure out |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 56 | * if the ROM SIP is good, second reason is that the |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 57 | * unknown bits are AGP related, which are dummy on K8T890 |
| 58 | */ |
| 59 | |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 60 | 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 Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 87 | print_debug(" VIA_X_2 device dump:\n"); |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 88 | dump_south(dev); |
| 89 | } |
| 90 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 91 | /* This fine tunes the HT link settings, which were loaded by ROM strap. */ |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 92 | static void host_ctrl_enable_k8m8xx(struct device *dev) { |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 93 | |
| 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 Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 100 | /* |
Rudolf Marek | 497c8ef | 2009-04-13 18:00:09 +0000 | [diff] [blame] | 101 | * NVRAM I/O base at K8T890_NVRAM_IO_BASE |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 102 | */ |
| 103 | |
Rudolf Marek | 497c8ef | 2009-04-13 18:00:09 +0000 | [diff] [blame] | 104 | 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 Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 109 | /* Arbitration control */ |
| 110 | pci_write_config8(dev, 0xa5, 0x3c); |
| 111 | |
Rudolf Marek | 0b0771d | 2008-09-19 22:58:59 +0000 | [diff] [blame] | 112 | /* Arbitration control 2, Enable C2NOW delay to PSTATECTL */ |
| 113 | pci_write_config8(dev, 0xa6, 0x83); |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 114 | |
| 115 | } |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 116 | void backup_top_of_ram(uint64_t ramtop) { |
| 117 | outl((u32) ramtop, K8T890_NVRAM_IO_BASE+K8T890_NVRAM_TOP_OF_RAM); |
Rudolf Marek | bcaea14 | 2010-11-22 22:00:52 +0000 | [diff] [blame] | 118 | } |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 119 | |
Rudolf Marek | 0f1dc4e | 2011-04-22 20:48:21 +0200 | [diff] [blame] | 120 | static struct pci_operations lops_pci = { |
| 121 | .set_subsystem = pci_dev_set_subsystem, |
| 122 | }; |
| 123 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 124 | static const struct device_operations host_ctrl_ops_t = { |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 125 | .read_resources = pci_dev_read_resources, |
| 126 | .set_resources = pci_dev_set_resources, |
| 127 | .enable_resources = pci_dev_enable_resources, |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 128 | .enable = host_ctrl_enable_k8t8xx, |
Rudolf Marek | 0f1dc4e | 2011-04-22 20:48:21 +0200 | [diff] [blame] | 129 | .ops_pci = &lops_pci, |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 132 | static 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 Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 136 | .enable = host_ctrl_enable_k8m8xx, |
Rudolf Marek | 0f1dc4e | 2011-04-22 20:48:21 +0200 | [diff] [blame] | 137 | .ops_pci = &lops_pci, |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 140 | static 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 | |
| 146 | static 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 | |
| 152 | static const struct pci_driver northbridge_driver_t890 __pci_driver = { |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 153 | .ops = &host_ctrl_ops_t, |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 154 | .vendor = PCI_VENDOR_ID_VIA, |
| 155 | .device = PCI_DEVICE_ID_VIA_K8T890CE_2, |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 156 | }; |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 157 | |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 158 | static const struct pci_driver northbridge_driver_m890 __pci_driver = { |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 159 | .ops = &host_ctrl_ops_m, |
| 160 | .vendor = PCI_VENDOR_ID_VIA, |
| 161 | .device = PCI_DEVICE_ID_VIA_K8M890CE_2, |
| 162 | }; |