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 |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 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> |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 26 | #include "k8x8xx.h" |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 27 | |
Stefan Reinauer | 2e2b84e | 2011-11-08 09:58:29 -0800 | [diff] [blame] | 28 | void k8x8xx_vt8237_mirrored_regs_fill(struct k8x8xx_vt8237_mirrored_regs *regs) |
| 29 | { |
| 30 | msr_t msr; |
| 31 | |
| 32 | regs->rom_shadow_ctrl_pg_c = 0xff; |
| 33 | regs->rom_shadow_ctrl_pg_d = 0xff; |
| 34 | regs->rom_shadow_ctrl_pg_e_memhole_smi_decoding = 0xff; |
| 35 | regs->rom_shadow_ctrl_pg_f_memhole = 0x30; |
| 36 | regs->smm_apic_decoding = 0x19; |
| 37 | msr = rdmsr(TOP_MEM); |
| 38 | regs->shadow_mem_ctrl = msr.lo >> 24; |
| 39 | regs->low_top_address = msr.lo >> 16; |
| 40 | } |
| 41 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 42 | /* We support here K8M890/K8T890 and VT8237R PCI1/Vlink which setup is not in separate |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 43 | * PCI device 0:11.7, but it is mapped to PCI 0:0.7 (0x70-0x7c for PCI1) |
Rudolf Marek | a6ddf25 | 2007-11-13 10:47:11 +0000 | [diff] [blame] | 44 | */ |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 45 | |
Florian Zumbiehl | 0802ad9 | 2011-11-01 20:19:01 +0100 | [diff] [blame] | 46 | void k8x8xx_vt8237r_cfg(struct device *dev, struct device *devsb) |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 47 | { |
Florian Zumbiehl | 1e1e859 | 2011-11-01 20:18:30 +0100 | [diff] [blame] | 48 | u8 regm3; |
| 49 | struct k8x8xx_vt8237_mirrored_regs mregs; |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 50 | |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 51 | pci_write_config8(dev, 0x70, 0xc2); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 52 | |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 53 | /* PCI Control */ |
Kyösti Mälkki | 35e1c86 | 2012-02-25 17:14:20 +0200 | [diff] [blame] | 54 | #if !CONFIG_SOUTHBRIDGE_VIA_SUBTYPE_K8T800_OLD |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 55 | pci_write_config8(dev, 0x72, 0xee); |
Florian Zumbiehl | 6a3e8d6 | 2011-11-01 20:19:38 +0100 | [diff] [blame] | 56 | #endif |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 57 | pci_write_config8(dev, 0x73, 0x01); |
Kyösti Mälkki | 35e1c86 | 2012-02-25 17:14:20 +0200 | [diff] [blame] | 58 | #if CONFIG_SOUTHBRIDGE_VIA_SUBTYPE_K8T800_OLD |
Florian Zumbiehl | 6a3e8d6 | 2011-11-01 20:19:38 +0100 | [diff] [blame] | 59 | pci_write_config8(dev, 0x74, 0x64); |
| 60 | pci_write_config8(dev, 0x75, 0x3f); |
| 61 | #else |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 62 | pci_write_config8(dev, 0x74, 0x24); |
| 63 | pci_write_config8(dev, 0x75, 0x0f); |
Florian Zumbiehl | 6a3e8d6 | 2011-11-01 20:19:38 +0100 | [diff] [blame] | 64 | #endif |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 65 | pci_write_config8(dev, 0x76, 0x50); |
Kyösti Mälkki | 35e1c86 | 2012-02-25 17:14:20 +0200 | [diff] [blame] | 66 | #if !CONFIG_SOUTHBRIDGE_VIA_SUBTYPE_K8T800_OLD |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 67 | pci_write_config8(dev, 0x77, 0x08); |
Florian Zumbiehl | 6a3e8d6 | 2011-11-01 20:19:38 +0100 | [diff] [blame] | 68 | #endif |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 69 | pci_write_config8(dev, 0x78, 0x01); |
| 70 | /* APIC on HT */ |
| 71 | pci_write_config8(dev, 0x7c, 0x7f); |
| 72 | pci_write_config8(dev, 0x7f, 0x02); |
| 73 | |
Florian Zumbiehl | 1e1e859 | 2011-11-01 20:18:30 +0100 | [diff] [blame] | 74 | k8x8xx_vt8237_mirrored_regs_fill(&mregs); |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 75 | |
Florian Zumbiehl | 1e1e859 | 2011-11-01 20:18:30 +0100 | [diff] [blame] | 76 | pci_write_config8(dev, 0x57, mregs.shadow_mem_ctrl); /* Shadow mem CTRL */ |
| 77 | pci_write_config8(dev, 0x61, mregs.rom_shadow_ctrl_pg_c); /* Shadow page C */ |
| 78 | pci_write_config8(dev, 0x62, mregs.rom_shadow_ctrl_pg_d); /* Shadow page D */ |
| 79 | pci_write_config8(dev, 0xe6, mregs.smm_apic_decoding); /* SMM and APIC decoding */ |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 80 | |
Florian Zumbiehl | 1e1e859 | 2011-11-01 20:18:30 +0100 | [diff] [blame] | 81 | regm3 = mregs.rom_shadow_ctrl_pg_e_memhole_smi_decoding; /* Shadow page E */ |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * All access bits for 0xE0000-0xEFFFF encode as just 2 bits! |
| 85 | * So the NB reg is quite inconsistent, we expect there only 0xff or 0x00, |
| 86 | * and write them to 0x63 7-6 but! VIA 8237A has the mirror at 0x64! |
| 87 | */ |
| 88 | if (regm3 == 0xff) |
| 89 | regm3 = 0xc0; |
| 90 | else |
| 91 | regm3 = 0x0; |
| 92 | |
| 93 | /* Shadow page F + memhole copy */ |
Florian Zumbiehl | 1e1e859 | 2011-11-01 20:18:30 +0100 | [diff] [blame] | 94 | pci_write_config8(dev, 0x63, regm3 | (mregs.rom_shadow_ctrl_pg_f_memhole & 0x3F)); |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 95 | |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | /** |
| 101 | * Setup the V-Link for VT8237R, 8X mode. |
| 102 | * |
| 103 | * For K8T890CF VIA recommends what is in VIA column, AW is award 8X: |
| 104 | * |
| 105 | * REG DEF AW VIA-8X VIA-4X |
| 106 | * ----------------------------- |
| 107 | * NB V-Link Manual Driving Control strobe 0xb5 0x46 0x46 0x88 0x88 |
| 108 | * NB V-Link Manual Driving Control - Data 0xb6 0x46 0x46 0x88 0x88 |
| 109 | * NB V-Link Receiving Strobe Delay 0xb7 0x02 0x02 0x61 0x01 |
| 110 | * NB V-Link Compensation Control bit4,0 (b5,b6) 0xb4 0x10 0x10 0x11 0x11 |
| 111 | * SB V-Link Strobe Drive Control 0xb9 0x00 0xa5 0x98 0x98 |
| 112 | * SB V-Link Data drive Control???? 0xba 0x00 0xbb 0x77 0x77 |
| 113 | * SB V-Link Receive Strobe Delay???? 0xbb 0x04 0x11 0x11 0x11 |
| 114 | * SB V-Link Compensation Control bit0 (use b9) 0xb8 0x00 0x01 0x01 0x01 |
| 115 | * V-Link CKG Control 0xb0 0x05 0x05 0x06 0x03 |
| 116 | * V-Link CKG Control 0xb1 0x05 0x05 0x01 0x03 |
| 117 | */ |
| 118 | |
| 119 | static void vt8237r_vlink_init(struct device *dev) |
| 120 | { |
| 121 | u8 reg; |
| 122 | |
| 123 | /* |
| 124 | * This init code is valid only for the VT8237R! For different |
| 125 | * sounthbridges (e.g. VT8237A, VT8237S, VT8237 (without plus R) |
| 126 | * and VT8251) a different init code is required. |
| 127 | */ |
| 128 | |
| 129 | pci_write_config8(dev, 0xb5, 0x88); |
| 130 | pci_write_config8(dev, 0xb6, 0x88); |
| 131 | pci_write_config8(dev, 0xb7, 0x61); |
| 132 | |
| 133 | reg = pci_read_config8(dev, 0xb4); |
| 134 | reg |= 0x11; |
| 135 | pci_write_config8(dev, 0xb4, reg); |
| 136 | |
| 137 | pci_write_config8(dev, 0xb9, 0x98); |
| 138 | pci_write_config8(dev, 0xba, 0x77); |
| 139 | pci_write_config8(dev, 0xbb, 0x11); |
| 140 | |
| 141 | reg = pci_read_config8(dev, 0xb8); |
| 142 | reg |= 0x1; |
| 143 | pci_write_config8(dev, 0xb8, reg); |
| 144 | |
| 145 | pci_write_config8(dev, 0xb0, 0x06); |
| 146 | pci_write_config8(dev, 0xb1, 0x01); |
| 147 | |
| 148 | /* Program V-link 8X 16bit full duplex, parity enabled. */ |
| 149 | pci_write_config8(dev, 0x48, 0xa3); |
| 150 | } |
| 151 | |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 152 | static void ctrl_init(struct device *dev) |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 153 | { |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 154 | |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 155 | print_debug("K8x8xx: Initializing V-Link to VT8237R sb: "); |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 156 | /* TODO: Fix some ordering issue fo V-link set Rx77[6] and PCI1_Rx4F[0] |
| 157 | should to 1 */ |
| 158 | |
| 159 | /* C2P Read ACK Return Priority */ |
| 160 | /* PCI CFG Address bits[27:24] are used as extended register address |
| 161 | bit[11:8] */ |
| 162 | |
Kyösti Mälkki | 35e1c86 | 2012-02-25 17:14:20 +0200 | [diff] [blame] | 163 | #if !CONFIG_SOUTHBRIDGE_VIA_SUBTYPE_K8T800_OLD |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 164 | pci_write_config8(dev, 0x47, 0x30); |
Florian Zumbiehl | 6a3e8d6 | 2011-11-01 20:19:38 +0100 | [diff] [blame] | 165 | #endif |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 166 | |
| 167 | /* VT8237R specific configuration other SB are done in their own directories */ |
| 168 | |
| 169 | device_t devsb = dev_find_device(PCI_VENDOR_ID_VIA, |
| 170 | PCI_DEVICE_ID_VIA_VT8237R_LPC, 0); |
| 171 | if (devsb) { |
| 172 | vt8237r_vlink_init(dev); |
Florian Zumbiehl | 0802ad9 | 2011-11-01 20:19:01 +0100 | [diff] [blame] | 173 | k8x8xx_vt8237r_cfg(dev, devsb); |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 174 | } else { |
| 175 | print_debug("VT8237R LPC not found !\n"); |
| 176 | return; |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 177 | } |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 178 | print_debug(" Done\n"); |
| 179 | print_debug(" VIA_X_7 device dump:\n"); |
| 180 | dump_south(dev); |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 181 | |
| 182 | } |
| 183 | |
Rudolf Marek | 0f1dc4e | 2011-04-22 20:48:21 +0200 | [diff] [blame] | 184 | static struct pci_operations lops_pci = { |
| 185 | .set_subsystem = pci_dev_set_subsystem, |
| 186 | }; |
| 187 | |
Uwe Hermann | 70ab323 | 2007-11-15 15:52:42 +0000 | [diff] [blame] | 188 | static const struct device_operations ctrl_ops = { |
| 189 | .read_resources = pci_dev_read_resources, |
| 190 | .set_resources = pci_dev_set_resources, |
| 191 | .enable_resources = pci_dev_enable_resources, |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 192 | .init = ctrl_init, |
Rudolf Marek | 0f1dc4e | 2011-04-22 20:48:21 +0200 | [diff] [blame] | 193 | .ops_pci = &lops_pci, |
Rudolf Marek | 1d4fc0c | 2007-10-22 19:59:57 +0000 | [diff] [blame] | 194 | }; |
| 195 | |
Patrick Georgi | efff733 | 2012-07-26 19:48:23 +0200 | [diff] [blame^] | 196 | static const unsigned short ctrl_ids[] = { |
| 197 | PCI_DEVICE_ID_VIA_K8T800_NB_SB_CTR, |
| 198 | PCI_DEVICE_ID_VIA_K8M800_NB_SB_CTR, |
| 199 | PCI_DEVICE_ID_VIA_K8T890CE_7, |
| 200 | PCI_DEVICE_ID_VIA_K8T890CF_7, |
| 201 | PCI_DEVICE_ID_VIA_K8M890CE_7, |
| 202 | 0 |
| 203 | }; |
| 204 | |
Alexandru Gagniuc | 025ead7 | 2011-02-16 13:43:00 +0000 | [diff] [blame] | 205 | static const struct pci_driver northbridge_driver_t800 __pci_driver = { |
| 206 | .ops = &ctrl_ops, |
| 207 | .vendor = PCI_VENDOR_ID_VIA, |
Patrick Georgi | efff733 | 2012-07-26 19:48:23 +0200 | [diff] [blame^] | 208 | .devices= ctrl_ids, |
Rudolf Marek | 316e07f | 2008-03-20 21:19:50 +0000 | [diff] [blame] | 209 | }; |