Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / southbridge / amd / amd8111 / amd8111.c
1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4 #include <device/pci_ids.h>
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;
12         unsigned reg_old, reg;
13
14         /* See if we are on the bus behind the amd8111 pci bridge */
15         bus_dev = dev->bus->dev;
16         if ((bus_dev->vendor == PCI_VENDOR_ID_AMD) &&
17             (bus_dev->device == PCI_DEVICE_ID_AMD_8111_PCI))
18         {
19                 unsigned devfn;
20                 devfn = bus_dev->path.pci.devfn + (1 << 3);
21                 lpc_dev = dev_find_slot(bus_dev->bus->secondary, devfn);
22                 index = ((dev->path.pci.devfn & ~7) >> 3) + 8;
23                 if (dev->path.pci.devfn == 2) { /* EHCI */
24                         index = 16;
25                 }
26         } else {
27                 unsigned devfn;
28                 devfn = (dev->path.pci.devfn) & ~7;
29                 lpc_dev = dev_find_slot(dev->bus->secondary, devfn);
30                 index = dev->path.pci.devfn & 7;
31         }
32         if ((!lpc_dev) || (index >= 17)) {
33                 return;
34         }
35         if ((lpc_dev->vendor != PCI_VENDOR_ID_AMD) ||
36             (lpc_dev->device != PCI_DEVICE_ID_AMD_8111_ISA))
37         {
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         }
44
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);
50                 }
51                 if (reg != reg_old) {
52                         pci_write_config16(lpc_dev, 0x48, reg);
53                 }
54         }
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                 }
64         }
65 }
66
67 struct chip_operations southbridge_amd_amd8111_ops = {
68         CHIP_NAME("AMD-8111 Southbridge")
69         /* This only called when this device is listed in the
70         * static device tree.
71         */
72         .enable_dev = amd8111_enable,
73 };