Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
| 2 | #include <device/device.h> |
| 3 | #include <device/pci.h> |
| 4 | #include <device/pci_ids.h> |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 5 | #include "amd8111.h" |
| 6 | |
| 7 | void amd8111_enable(device_t dev) |
| 8 | { |
| 9 | device_t lpc_dev; |
| 10 | device_t bus_dev; |
| 11 | unsigned index; |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 12 | unsigned reg_old, reg; |
Yinghai Lu | f19e2c7 | 2004-10-21 01:52:21 +0000 | [diff] [blame] | 13 | |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 14 | /* See if we are on the bus behind the amd8111 pci bridge */ |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 15 | bus_dev = dev->bus->dev; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 16 | if ((bus_dev->vendor == PCI_VENDOR_ID_AMD) && |
| 17 | (bus_dev->device == PCI_DEVICE_ID_AMD_8111_PCI)) |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 18 | { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 19 | unsigned devfn; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 20 | devfn = bus_dev->path.pci.devfn + (1 << 3); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 21 | lpc_dev = dev_find_slot(bus_dev->bus->secondary, devfn); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 22 | index = ((dev->path.pci.devfn & ~7) >> 3) + 8; |
| 23 | if (dev->path.pci.devfn == 2) { /* EHCI */ |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 24 | index = 16; |
| 25 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 26 | } else { |
| 27 | unsigned devfn; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 28 | devfn = (dev->path.pci.devfn) & ~7; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 29 | lpc_dev = dev_find_slot(dev->bus->secondary, devfn); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 30 | index = dev->path.pci.devfn & 7; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 31 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 32 | if ((!lpc_dev) || (index >= 17)) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 33 | return; |
| 34 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 35 | if ((lpc_dev->vendor != PCI_VENDOR_ID_AMD) || |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 36 | (lpc_dev->device != PCI_DEVICE_ID_AMD_8111_ISA)) |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 37 | { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 38 | uint32_t id; |
| 39 | id = pci_read_config32(lpc_dev, PCI_VENDOR_ID); |
| 40 | if (id != (PCI_VENDOR_ID_AMD | (PCI_DEVICE_ID_AMD_8111_ISA << 16))) { |
| 41 | return; |
| 42 | } |
| 43 | } |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 44 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 45 | if (index < 16) { |
| 46 | reg = reg_old = pci_read_config16(lpc_dev, 0x48); |
| 47 | reg &= ~(1 << index); |
| 48 | if (dev->enabled) { |
| 49 | reg |= (1 << index); |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 50 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 51 | if (reg != reg_old) { |
| 52 | pci_write_config16(lpc_dev, 0x48, reg); |
| 53 | } |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 54 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 55 | else if (index == 16) { |
| 56 | reg = reg_old = pci_read_config8(lpc_dev, 0x47); |
| 57 | reg &= ~(1 << 7); |
| 58 | if (!dev->enabled) { |
| 59 | reg |= (1 << 7); |
| 60 | } |
| 61 | if (reg != reg_old) { |
| 62 | pci_write_config8(lpc_dev, 0x47, reg); |
| 63 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 64 | } |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 67 | struct chip_operations southbridge_amd_amd8111_ops = { |
Uwe Hermann | a7aa29b | 2006-11-05 18:50:49 +0000 | [diff] [blame] | 68 | CHIP_NAME("AMD-8111 Southbridge") |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 69 | /* This only called when this device is listed in the |
Jason Schildt | ab327a3 | 2005-10-13 00:44:34 +0000 | [diff] [blame] | 70 | * static device tree. |
| 71 | */ |
Li-Ta Lo | 9e17d4f | 2004-05-13 16:49:53 +0000 | [diff] [blame] | 72 | .enable_dev = amd8111_enable, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 73 | }; |