Martin Roth | ebace9f | 2018-05-26 18:56:17 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 14 | #include <console/console.h> |
| 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
| 17 | #include <device/pci_ids.h> |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 18 | #include "amd8111.h" |
| 19 | |
Elyes HAOUAS | 39733a0 | 2018-05-19 14:45:20 +0200 | [diff] [blame] | 20 | void amd8111_enable(struct device *dev) |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 21 | { |
Elyes HAOUAS | 39733a0 | 2018-05-19 14:45:20 +0200 | [diff] [blame] | 22 | struct device *lpc_dev; |
| 23 | struct device *bus_dev; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 24 | unsigned index; |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 25 | unsigned reg_old, reg; |
Yinghai Lu | f19e2c7 | 2004-10-21 01:52:21 +0000 | [diff] [blame] | 26 | |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 27 | /* See if we are on the bus behind the amd8111 pci bridge */ |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 28 | bus_dev = dev->bus->dev; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 29 | if ((bus_dev->vendor == PCI_VENDOR_ID_AMD) && |
| 30 | (bus_dev->device == PCI_DEVICE_ID_AMD_8111_PCI)) |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 31 | { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 32 | unsigned devfn; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 33 | devfn = bus_dev->path.pci.devfn + (1 << 3); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 34 | lpc_dev = dev_find_slot(bus_dev->bus->secondary, devfn); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 35 | index = ((dev->path.pci.devfn & ~7) >> 3) + 8; |
| 36 | if (dev->path.pci.devfn == 2) { /* EHCI */ |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 37 | index = 16; |
| 38 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 39 | } else { |
| 40 | unsigned devfn; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 41 | devfn = (dev->path.pci.devfn) & ~7; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 42 | lpc_dev = dev_find_slot(dev->bus->secondary, devfn); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 43 | index = dev->path.pci.devfn & 7; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 44 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 45 | if ((!lpc_dev) || (index >= 17)) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 46 | return; |
| 47 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 48 | if ((lpc_dev->vendor != PCI_VENDOR_ID_AMD) || |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 49 | (lpc_dev->device != PCI_DEVICE_ID_AMD_8111_ISA)) |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 50 | { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 51 | uint32_t id; |
| 52 | id = pci_read_config32(lpc_dev, PCI_VENDOR_ID); |
| 53 | if (id != (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_AMD_8111_ISA << 16))) { |
| 54 | return; |
| 55 | } |
| 56 | } |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 57 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 58 | if (index < 16) { |
| 59 | reg = reg_old = pci_read_config16(lpc_dev, 0x48); |
| 60 | reg &= ~(1 << index); |
| 61 | if (dev->enabled) { |
| 62 | reg |= (1 << index); |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 63 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 64 | if (reg != reg_old) { |
| 65 | pci_write_config16(lpc_dev, 0x48, reg); |
| 66 | } |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 67 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 68 | else if (index == 16) { |
| 69 | reg = reg_old = pci_read_config8(lpc_dev, 0x47); |
| 70 | reg &= ~(1 << 7); |
| 71 | if (!dev->enabled) { |
| 72 | reg |= (1 << 7); |
| 73 | } |
| 74 | if (reg != reg_old) { |
| 75 | pci_write_config8(lpc_dev, 0x47, reg); |
| 76 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 77 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 80 | struct chip_operations southbridge_amd_amd8111_ops = { |
Uwe Hermann | a7aa29b | 2006-11-05 18:50:49 +0000 | [diff] [blame] | 81 | CHIP_NAME("AMD-8111 Southbridge") |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 82 | /* This only called when this device is listed in the |
Jason Schildt | ab327a3 | 2005-10-13 00:44:34 +0000 | [diff] [blame] | 83 | * static device tree. |
| 84 | */ |
Li-Ta Lo | 9e17d4f | 2004-05-13 16:49:53 +0000 | [diff] [blame] | 85 | .enable_dev = amd8111_enable, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 86 | }; |