arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | 8af6d55 | 2010-10-17 19:13:18 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2004 Tyan Computer |
| 5 | * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 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. |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 18 | #include <arch/io.h> |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <device/pci_ops.h> |
Kyösti Mälkki | 413e3da | 2015-02-03 08:05:55 +0200 | [diff] [blame] | 23 | #include "chip.h" |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 24 | |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 25 | static u32 final_reg; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 26 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 27 | static device_t find_lpc_dev(device_t dev, unsigned devfn) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 28 | { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 29 | device_t lpc_dev; |
| 30 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 31 | lpc_dev = dev_find_slot(dev->bus->secondary, devfn); |
| 32 | if (!lpc_dev) |
| 33 | return lpc_dev; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 34 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 35 | if ((lpc_dev->vendor != PCI_VENDOR_ID_NVIDIA) |
| 36 | || ((lpc_dev->device != PCI_DEVICE_ID_NVIDIA_CK804_LPC) |
| 37 | && (lpc_dev->device != PCI_DEVICE_ID_NVIDIA_CK804_PRO) |
| 38 | && (lpc_dev->device != PCI_DEVICE_ID_NVIDIA_CK804_SLAVE))) |
| 39 | { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 40 | u32 id; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 41 | id = pci_read_config32(lpc_dev, PCI_VENDOR_ID); |
| 42 | if ((id != (PCI_VENDOR_ID_NVIDIA | |
| 43 | (PCI_DEVICE_ID_NVIDIA_CK804_LPC << 16))) |
| 44 | && (id != (PCI_VENDOR_ID_NVIDIA | |
| 45 | (PCI_DEVICE_ID_NVIDIA_CK804_PRO << 16))) |
| 46 | && (id != (PCI_VENDOR_ID_NVIDIA | |
| 47 | (PCI_DEVICE_ID_NVIDIA_CK804_SLAVE << 16)))) |
| 48 | { |
| 49 | lpc_dev = 0; |
| 50 | } |
| 51 | } |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 52 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 53 | return lpc_dev; |
| 54 | } |
| 55 | |
Kyösti Mälkki | 413e3da | 2015-02-03 08:05:55 +0200 | [diff] [blame] | 56 | static void ck804_enable(device_t dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 57 | { |
| 58 | device_t lpc_dev; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 59 | unsigned index = 0, index2 = 0, deviceid, vendorid, devfn; |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 60 | u32 reg_old, reg; |
| 61 | u8 byte; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 62 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 63 | struct southbridge_nvidia_ck804_config *conf; |
| 64 | conf = dev->chip_info; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 65 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 66 | if (dev->device == 0x0000) { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 67 | vendorid = pci_read_config32(dev, PCI_VENDOR_ID); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 68 | deviceid = (vendorid >> 16) & 0xffff; |
| 69 | /* vendorid &= 0xffff; */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 70 | } else { |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 71 | /* vendorid = dev->vendor; */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 72 | deviceid = dev->device; |
| 73 | } |
| 74 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 75 | devfn = (dev->path.pci.devfn) & ~7; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 76 | switch (deviceid) { |
| 77 | case PCI_DEVICE_ID_NVIDIA_CK804_SM: |
| 78 | index = 16; |
| 79 | break; |
| 80 | case PCI_DEVICE_ID_NVIDIA_CK804_USB: |
| 81 | devfn -= (1 << 3); |
| 82 | index = 8; |
| 83 | break; |
| 84 | case PCI_DEVICE_ID_NVIDIA_CK804_USB2: |
| 85 | devfn -= (1 << 3); |
| 86 | index = 20; |
| 87 | break; |
| 88 | case PCI_DEVICE_ID_NVIDIA_CK804_NIC: |
| 89 | devfn -= (9 << 3); |
| 90 | index = 10; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 91 | break; |
| 92 | case PCI_DEVICE_ID_NVIDIA_CK804_NIC_BRIDGE: |
| 93 | devfn -= (9 << 3); |
| 94 | index = 10; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 95 | break; |
| 96 | case PCI_DEVICE_ID_NVIDIA_CK804_ACI: |
| 97 | devfn -= (3 << 3); |
| 98 | index = 12; |
| 99 | break; |
| 100 | case PCI_DEVICE_ID_NVIDIA_CK804_MCI: |
| 101 | devfn -= (3 << 3); |
| 102 | index = 13; |
| 103 | break; |
| 104 | case PCI_DEVICE_ID_NVIDIA_CK804_IDE: |
| 105 | devfn -= (5 << 3); |
| 106 | index = 14; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 107 | break; |
| 108 | case PCI_DEVICE_ID_NVIDIA_CK804_SATA0: |
| 109 | devfn -= (6 << 3); |
| 110 | index = 22; |
| 111 | break; |
| 112 | case PCI_DEVICE_ID_NVIDIA_CK804_SATA1: |
| 113 | devfn -= (7 << 3); |
| 114 | index = 18; |
| 115 | break; |
| 116 | case PCI_DEVICE_ID_NVIDIA_CK804_PCI: |
| 117 | devfn -= (8 << 3); |
| 118 | index = 15; |
| 119 | break; |
| 120 | case PCI_DEVICE_ID_NVIDIA_CK804_PCI_E: |
| 121 | devfn -= (0xa << 3); |
| 122 | index2 = 19; |
| 123 | break; |
| 124 | default: |
| 125 | index = 0; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 128 | if (index2 != 0) { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 129 | int i; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 130 | for (i = 0; i < 4; i++) { |
| 131 | lpc_dev = find_lpc_dev(dev, devfn - (i << 3)); |
| 132 | if (!lpc_dev) |
| 133 | continue; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 134 | index2 -= i; |
| 135 | break; |
| 136 | } |
| 137 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 138 | if (lpc_dev) { |
| 139 | reg_old = reg = pci_read_config32(lpc_dev, 0xe4); |
| 140 | if (!dev->enabled) |
| 141 | reg |= (1 << index2); |
| 142 | if (reg != reg_old) |
| 143 | pci_write_config32(lpc_dev, 0xe4, reg); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | index2 = 0; |
| 147 | return; |
| 148 | } |
| 149 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 150 | lpc_dev = find_lpc_dev(dev, devfn); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 151 | if (!lpc_dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 152 | return; |
| 153 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 154 | if (index == 0) { |
| 155 | final_reg = pci_read_config32(lpc_dev, 0xe8); |
| 156 | final_reg &= ~((1 << 16) | (1 << 8) | (1 << 20) | (1 << 10) |
| 157 | | (1 << 12) | (1 << 13) | (1 << 14) | (1 << 22) |
| 158 | | (1 << 18) | (1 << 15)); |
| 159 | pci_write_config32(lpc_dev, 0xe8, final_reg); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 160 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 161 | reg_old = reg = pci_read_config32(lpc_dev, 0xe4); |
| 162 | reg |= (1 << 20); |
| 163 | if (reg != reg_old) |
| 164 | pci_write_config32(lpc_dev, 0xe4, reg); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 165 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 166 | byte = pci_read_config8(lpc_dev, 0x74); |
| 167 | byte |= ((1 << 1)); |
| 168 | pci_write_config8(dev, 0x74, byte); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 169 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 170 | byte = pci_read_config8(lpc_dev, 0xdd); |
| 171 | byte |= ((1 << 0) | (1 << 3)); |
| 172 | pci_write_config8(dev, 0xdd, byte); |
| 173 | |
| 174 | return; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 177 | if (!dev->enabled) |
| 178 | final_reg |= (1 << index); |
| 179 | |
| 180 | if (index == 10) { |
| 181 | reg_old = pci_read_config32(lpc_dev, 0xe8); |
| 182 | if (final_reg != reg_old) |
| 183 | pci_write_config32(lpc_dev, 0xe8, final_reg); |
| 184 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Jonathan Kollasch | c7f3f80 | 2010-10-29 15:56:04 +0000 | [diff] [blame] | 187 | static void ck804_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 188 | { |
| 189 | pci_write_config32(dev, 0x40, |
| 190 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 191 | } |
| 192 | |
| 193 | struct pci_operations ck804_pci_ops = { |
| 194 | .set_subsystem = ck804_set_subsystem, |
| 195 | }; |
| 196 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 197 | struct chip_operations southbridge_nvidia_ck804_ops = { |
Uwe Hermann | a7aa29b | 2006-11-05 18:50:49 +0000 | [diff] [blame] | 198 | CHIP_NAME("NVIDIA CK804 Southbridge") |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 199 | .enable_dev = ck804_enable, |
| 200 | }; |