Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 3 | |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 4 | #include <amdblocks/acpimmio.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 5 | #include <device/mmio.h> |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 6 | #include <device/device.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 7 | #include <device/pci.h> /* device_operations */ |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 9 | #include <device/pci_ids.h> |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 10 | #include <bootstate.h> |
Kerry She | 991f880 | 2011-06-01 01:56:49 +0000 | [diff] [blame] | 11 | #include <arch/ioapic.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 12 | #include <device/smbus.h> /* smbus_bus_operations */ |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 13 | #include <pc80/mc146818rtc.h> |
Edward O'Callaghan | e61dd0f | 2014-05-06 23:53:09 +1000 | [diff] [blame] | 14 | #include <pc80/i8254.h> |
| 15 | #include <pc80/i8259.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 16 | #include <console/console.h> /* printk */ |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame^] | 17 | #include <acpi/acpi.h> |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 18 | #include <device/pci_ehci.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 19 | #include "lpc.h" /* lpc_read_resources */ |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 20 | #include "SBPLATFORM.h" /* Platform Specific Definitions */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 21 | #include "cfg.h" /* sb800 Cimx configuration */ |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 22 | #include "chip.h" /* struct southbridge_amd_cimx_sb800_config */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 23 | #include "sb_cimx.h" /* AMD CIMX wrapper entries */ |
Dave Frodin | 23023a5 | 2012-11-13 07:09:12 -0700 | [diff] [blame] | 24 | #include "smbus.h" |
Martin Roth | e899e51 | 2012-12-05 16:07:11 -0700 | [diff] [blame] | 25 | #include "fan.h" |
Tobias Diedrich | d8a2c1f | 2017-02-20 02:46:19 +0100 | [diff] [blame] | 26 | #include "pci_devs.h" |
Stefan Reinauer | 13e4182 | 2015-04-27 14:02:36 -0700 | [diff] [blame] | 27 | #include <southbridge/amd/common/amd_pci_util.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 28 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 29 | static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config |
| 30 | static AMDSBCFG *sb_config = &sb_late_cfg; |
| 31 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 32 | /** |
| 33 | * @brief Entry point of Southbridge CIMx callout |
| 34 | * |
| 35 | * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig) |
| 36 | * |
| 37 | * @param[in] func Southbridge CIMx Function ID. |
| 38 | * @param[in] data Southbridge Input Data. |
Martin Roth | 6355cbf | 2015-01-04 15:22:26 -0700 | [diff] [blame] | 39 | * @param[in] config Southbridge configuration structure pointer. |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 40 | * |
| 41 | */ |
Elyes HAOUAS | 251279c | 2018-07-08 12:41:56 +0200 | [diff] [blame] | 42 | static u32 sb800_callout_entry(u32 func, u32 data, void *config) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 43 | { |
| 44 | u32 ret = 0; |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 45 | printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 46 | switch (func) { |
| 47 | case CB_SBGPP_RESET_ASSERT: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 48 | break; |
| 49 | |
| 50 | case CB_SBGPP_RESET_DEASSERT: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 51 | break; |
| 52 | |
| 53 | case IMC_FIRMWARE_FAIL: |
| 54 | break; |
| 55 | |
| 56 | default: |
| 57 | break; |
| 58 | } |
| 59 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 60 | printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 61 | return ret; |
| 62 | } |
| 63 | |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 64 | #define HOST_CAP 0x00 /* host capabilities */ |
| 65 | #define HOST_CTL 0x04 /* global host control */ |
| 66 | #define HOST_IRQ_STAT 0x08 /* interrupt status */ |
| 67 | #define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */ |
| 68 | |
| 69 | #define HOST_CTL_AHCI_EN (1 << 31) /* AHCI enabled */ |
| 70 | static void ahci_raid_init(struct device *dev) |
| 71 | { |
| 72 | u8 irq = 0; |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame] | 73 | void *bar5; |
| 74 | u32 caps, ports, val; |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 75 | |
| 76 | val = pci_read_config16(dev, PCI_CLASS_DEVICE); |
| 77 | if (val == PCI_CLASS_STORAGE_SATA) { |
| 78 | printk(BIOS_DEBUG, "AHCI controller "); |
| 79 | } else if (val == PCI_CLASS_STORAGE_RAID) { |
| 80 | printk(BIOS_DEBUG, "RAID controller "); |
| 81 | } else { |
| 82 | printk(BIOS_WARNING, "device class:%x, neither in ahci or raid mode\n", val); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | irq = pci_read_config8(dev, PCI_INTERRUPT_LINE); |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame] | 87 | bar5 = (void *)(uintptr_t)pci_read_config32(dev, PCI_BASE_ADDRESS_5); |
| 88 | printk(BIOS_DEBUG, "IOMEM base: %p, IRQ: 0x%X\n", bar5, irq); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 89 | |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame] | 90 | caps = read32(bar5 + HOST_CAP); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 91 | caps = (caps & 0x1F) + 1; |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame] | 92 | ports= read32(bar5 + HOST_PORTS_IMPL); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 93 | printk(BIOS_DEBUG, "Number of Ports: 0x%x, Port implemented(bit map): 0x%x\n", caps, ports); |
| 94 | |
| 95 | /* make sure ahci is enabled */ |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame] | 96 | val = read32(bar5 + HOST_CTL); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 97 | if (!(val & HOST_CTL_AHCI_EN)) { |
Stefan Reinauer | 12bce3f | 2015-06-18 01:17:38 -0700 | [diff] [blame] | 98 | write32(bar5 + HOST_CTL, val | HOST_CTL_AHCI_EN); |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | dev->command |= PCI_COMMAND_MASTER; |
| 102 | pci_write_config8(dev, PCI_COMMAND, dev->command); |
| 103 | printk(BIOS_DEBUG, "AHCI/RAID controller initialized\n"); |
| 104 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 105 | |
| 106 | static struct pci_operations lops_pci = { |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 107 | .set_subsystem = pci_dev_set_subsystem, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 110 | static void lpc_init(struct device *dev) |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 111 | { |
| 112 | printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - Start.\n"); |
| 113 | |
Gabe Black | 03abaee21 | 2014-04-30 21:31:44 -0700 | [diff] [blame] | 114 | cmos_check_update_date(); |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 115 | |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 116 | /* Initialize the real time clock. |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 117 | * The 0 argument tells cmos_init not to |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 118 | * update CMOS unless it is invalid. |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 119 | * 1 tells cmos_init to always initialize the CMOS. |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 120 | */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 121 | cmos_init(0); |
Mike Loptien | ac529b1 | 2013-02-22 13:18:31 -0700 | [diff] [blame] | 122 | |
Edward O'Callaghan | e61dd0f | 2014-05-06 23:53:09 +1000 | [diff] [blame] | 123 | setup_i8259(); /* Initialize i8259 pic */ |
| 124 | setup_i8254(); /* Initialize i8254 timers */ |
| 125 | |
zbao | 366f0fc | 2012-08-03 16:58:53 +0800 | [diff] [blame] | 126 | printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - End.\n"); |
| 127 | } |
| 128 | |
Vladimir Serbinenko | 2a19fb1 | 2014-10-02 20:09:19 +0200 | [diff] [blame] | 129 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 130 | { |
| 131 | /* Just a dummy */ |
| 132 | return current; |
| 133 | } |
| 134 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 135 | static const char *lpc_acpi_name(const struct device *dev) |
Tobias Diedrich | d8a2c1f | 2017-02-20 02:46:19 +0100 | [diff] [blame] | 136 | { |
| 137 | if (dev->path.type != DEVICE_PATH_PCI) |
| 138 | return NULL; |
| 139 | |
| 140 | switch (dev->path.pci.devfn) { |
| 141 | /* DSDT: acpi/lpc.asl */ |
| 142 | case LPC_DEVFN: |
| 143 | return "LIBR"; |
| 144 | } |
| 145 | |
| 146 | return NULL; |
| 147 | } |
| 148 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 149 | static struct device_operations lpc_ops = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 150 | .read_resources = lpc_read_resources, |
| 151 | .set_resources = lpc_set_resources, |
| 152 | .enable_resources = pci_dev_enable_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 153 | #if CONFIG(HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 2a19fb1 | 2014-10-02 20:09:19 +0200 | [diff] [blame] | 154 | .write_acpi_tables = acpi_write_hpet, |
| 155 | #endif |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 156 | .init = lpc_init, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 157 | .scan_bus = scan_static_bus, |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 158 | .ops_pci = &lops_pci, |
Tobias Diedrich | d8a2c1f | 2017-02-20 02:46:19 +0100 | [diff] [blame] | 159 | .acpi_name = lpc_acpi_name, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static const struct pci_driver lpc_driver __pci_driver = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 163 | .ops = &lpc_ops, |
| 164 | .vendor = PCI_VENDOR_ID_ATI, |
| 165 | .device = PCI_DEVICE_ID_ATI_SB800_LPC, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 168 | static struct device_operations sata_ops = { |
| 169 | .read_resources = pci_dev_read_resources, |
| 170 | .set_resources = pci_dev_set_resources, |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 171 | .enable_resources = pci_dev_enable_resources, |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 172 | .init = ahci_raid_init, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 173 | .ops_pci = &lops_pci, |
| 174 | }; |
| 175 | |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 176 | static const struct pci_driver ahci_driver __pci_driver = { |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 177 | .ops = &sata_ops, |
| 178 | .vendor = PCI_VENDOR_ID_ATI, |
Scott Duplichan | f191c72 | 2011-05-15 21:38:08 +0000 | [diff] [blame] | 179 | .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
Kerry Sheh | 0e6344e | 2011-10-12 11:42:59 +0800 | [diff] [blame] | 182 | static const struct pci_driver raid_driver __pci_driver = { |
| 183 | .ops = &sata_ops, |
| 184 | .vendor = PCI_VENDOR_ID_ATI, |
| 185 | .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID, |
| 186 | }; |
| 187 | static const struct pci_driver raid5_driver __pci_driver = { |
| 188 | .ops = &sata_ops, |
| 189 | .vendor = PCI_VENDOR_ID_ATI, |
| 190 | .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5, |
| 191 | }; |
| 192 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 193 | static struct device_operations usb_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 194 | .read_resources = pci_ehci_read_resources, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 195 | .set_resources = pci_dev_set_resources, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 196 | .enable_resources = pci_dev_enable_resources, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 197 | .ops_pci = &lops_pci, |
| 198 | }; |
| 199 | |
| 200 | /* |
Elyes HAOUAS | 44f558e | 2020-02-24 13:26:04 +0100 | [diff] [blame] | 201 | * The pci id of USB ctrl 0 and 1 are the same. |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 202 | */ |
| 203 | static const struct pci_driver usb_ohci123_driver __pci_driver = { |
| 204 | .ops = &usb_ops, |
| 205 | .vendor = PCI_VENDOR_ID_ATI, |
| 206 | .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */ |
| 207 | }; |
| 208 | |
| 209 | static const struct pci_driver usb_ehci123_driver __pci_driver = { |
| 210 | .ops = &usb_ops, |
| 211 | .vendor = PCI_VENDOR_ID_ATI, |
| 212 | .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */ |
| 213 | }; |
| 214 | |
| 215 | static const struct pci_driver usb_ohci4_driver __pci_driver = { |
| 216 | .ops = &usb_ops, |
| 217 | .vendor = PCI_VENDOR_ID_ATI, |
| 218 | .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */ |
| 219 | }; |
| 220 | |
| 221 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 222 | static struct device_operations azalia_ops = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 223 | .read_resources = pci_dev_read_resources, |
| 224 | .set_resources = pci_dev_set_resources, |
| 225 | .enable_resources = pci_dev_enable_resources, |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 226 | .ops_pci = &lops_pci, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | static const struct pci_driver azalia_driver __pci_driver = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 230 | .ops = &azalia_ops, |
| 231 | .vendor = PCI_VENDOR_ID_ATI, |
| 232 | .device = PCI_DEVICE_ID_ATI_SB800_HDA, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 236 | static struct device_operations gec_ops = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 237 | .read_resources = pci_dev_read_resources, |
| 238 | .set_resources = pci_dev_set_resources, |
| 239 | .enable_resources = pci_dev_enable_resources, |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 240 | .ops_pci = &lops_pci, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | static const struct pci_driver gec_driver __pci_driver = { |
Elyes HAOUAS | ba28e8d | 2016-08-31 19:22:16 +0200 | [diff] [blame] | 244 | .ops = &gec_ops, |
| 245 | .vendor = PCI_VENDOR_ID_ATI, |
| 246 | .device = PCI_DEVICE_ID_ATI_SB800_GEC, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
Kerry She | 3e706b6 | 2011-06-24 22:52:15 +0800 | [diff] [blame] | 249 | /** |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 250 | * Fill build time defaults. |
| 251 | */ |
| 252 | static void sb800_init(void *chip_info) |
| 253 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 254 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 255 | sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry; |
| 256 | sb800_cimx_config(sb_config); |
Kyösti Mälkki | 24501ca | 2015-02-07 17:38:45 +0200 | [diff] [blame] | 257 | |
Paul Menzel | 114a948 | 2015-10-25 22:27:42 +0100 | [diff] [blame] | 258 | /* Initially enable all GPP ports 0 to 3 */ |
Kyösti Mälkki | 24501ca | 2015-02-07 17:38:45 +0200 | [diff] [blame] | 259 | abcfg_reg(0xc0, 0x01FF, 0x0F4); |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 263 | * South Bridge CIMx ramstage entry point wrapper. |
| 264 | */ |
| 265 | void sb_Before_Pci_Init(void) |
| 266 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 267 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 268 | sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT; |
| 269 | AmdSbDispatcher(sb_config); |
| 270 | } |
| 271 | |
| 272 | void sb_After_Pci_Init(void) |
| 273 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 274 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 275 | sb_config->StdHeader.Func = SB_AFTER_PCI_INIT; |
| 276 | AmdSbDispatcher(sb_config); |
| 277 | } |
| 278 | |
| 279 | void sb_Mid_Post_Init(void) |
| 280 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 281 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 282 | sb_config->StdHeader.Func = SB_MID_POST_INIT; |
| 283 | AmdSbDispatcher(sb_config); |
| 284 | } |
| 285 | |
| 286 | void sb_Late_Post(void) |
| 287 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 288 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 289 | sb_config->StdHeader.Func = SB_LATE_POST_INIT; |
| 290 | AmdSbDispatcher(sb_config); |
| 291 | } |
| 292 | |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 293 | void sb_Before_Pci_Restore_Init(void) |
| 294 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 295 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 296 | sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT; |
| 297 | AmdSbDispatcher(sb_config); |
| 298 | } |
| 299 | |
| 300 | void sb_After_Pci_Restore_Init(void) |
| 301 | { |
Kyösti Mälkki | 1498efe | 2017-03-09 16:25:24 +0200 | [diff] [blame] | 302 | printk(BIOS_DEBUG, "SB800: %s\n", __func__); |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 303 | sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT; |
| 304 | AmdSbDispatcher(sb_config); |
| 305 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 306 | |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 307 | /* |
| 308 | * Update the PCI devices with a valid IRQ number |
| 309 | * that is set in the mainboard PCI_IRQ structures. |
| 310 | */ |
| 311 | static void set_pci_irqs(void *unused) |
| 312 | { |
| 313 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 314 | write_pci_int_table(); |
| 315 | |
| 316 | /* Write IRQs for all devicetree enabled devices */ |
| 317 | write_pci_cfg_irqs(); |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * Hook this function into the PCI state machine |
| 322 | * on entry into BS_DEV_ENABLE. |
| 323 | */ |
Aaron Durbin | 9ef9d85 | 2015-03-16 17:30:09 -0500 | [diff] [blame] | 324 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |
Mike Loptien | c93a75a | 2014-06-06 15:16:29 -0600 | [diff] [blame] | 325 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 326 | /** |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 327 | * @brief SB Cimx entry point sbBeforePciInit wrapper |
| 328 | */ |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 329 | static void sb800_enable(struct device *dev) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 330 | { |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 331 | struct southbridge_amd_cimx_sb800_config *sb_chip = |
| 332 | (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 333 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 334 | switch (dev->path.pci.devfn) { |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 335 | case PCI_DEVFN(0x11, 0): /* 0:11.0 SATA */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 336 | if (dev->enabled) { |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 337 | sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED; |
Elyes HAOUAS | 0f8b8d9 | 2019-01-03 10:23:28 +0100 | [diff] [blame] | 338 | if (sb_chip->boot_switch_sata_ide == 1) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 339 | sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary. |
Elyes HAOUAS | 0f8b8d9 | 2019-01-03 10:23:28 +0100 | [diff] [blame] | 340 | else if (sb_chip->boot_switch_sata_ide == 0) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 341 | sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary. |
| 342 | } else { |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 343 | sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 344 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 345 | break; |
| 346 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 347 | case PCI_DEVFN(0x14, 0): /* 0:14:0 SMBUS */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 348 | clear_ioapic(VIO_APIC_VADDR); |
Kyösti Mälkki | 35546de | 2014-04-17 15:07:32 +0300 | [diff] [blame] | 349 | /* Assign the ioapic ID the next available number after the processor core local APIC IDs */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 350 | setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 351 | break; |
| 352 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 353 | case PCI_DEVFN(0x14, 1): /* 0:14:1 IDE */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 354 | break; |
| 355 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 356 | case PCI_DEVFN(0x14, 2): /* 0:14:2 HDA */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 357 | if (dev->enabled) { |
Elyes HAOUAS | 0f8b8d9 | 2019-01-03 10:23:28 +0100 | [diff] [blame] | 358 | if (sb_config->AzaliaController == AZALIA_DISABLE) { |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 359 | sb_config->AzaliaController = AZALIA_AUTO; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 360 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 361 | } else { |
Elyes HAOUAS | b0f1988 | 2018-06-09 11:59:00 +0200 | [diff] [blame] | 362 | sb_config->AzaliaController = AZALIA_DISABLE; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 363 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 364 | break; |
| 365 | |
| 366 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 367 | case PCI_DEVFN(0x14, 3): /* 0:14:3 LPC */ |
Martin Roth | e899e51 | 2012-12-05 16:07:11 -0700 | [diff] [blame] | 368 | /* Initialize the fans */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 369 | #if CONFIG(SB800_IMC_FAN_CONTROL) |
Martin Roth | e899e51 | 2012-12-05 16:07:11 -0700 | [diff] [blame] | 370 | init_sb800_IMC_fans(dev); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 371 | #elif CONFIG(SB800_MANUAL_FAN_CONTROL) |
Martin Roth | e899e51 | 2012-12-05 16:07:11 -0700 | [diff] [blame] | 372 | init_sb800_MANUAL_fans(dev); |
| 373 | #endif |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 374 | break; |
| 375 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 376 | case PCI_DEVFN(0x14, 4): /* 0:14:4 PCI */ |
Kyösti Mälkki | 486c05f | 2015-01-17 18:08:40 +0200 | [diff] [blame] | 377 | /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0] |
| 378 | * 'PCIDisable' set to 0 to enable P2P bridge. |
| 379 | * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins |
| 380 | * to function as GPIO {GPIO 35:0}. |
| 381 | */ |
Kyösti Mälkki | 0b87bb7 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 382 | if (!sb_chip->disconnect_pcib && dev->enabled) |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 383 | pm_write8(0xea, pm_read8(0xea) & 0xfe); |
Kyösti Mälkki | 486c05f | 2015-01-17 18:08:40 +0200 | [diff] [blame] | 384 | else |
Michał Żygowski | 287ce5f | 2019-12-01 17:41:23 +0100 | [diff] [blame] | 385 | pm_write8(0xea, (pm_read8(0xea) & 0xfe) | 1); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 386 | break; |
| 387 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 388 | case PCI_DEVFN(0x14, 6): /* 0:14:6 GEC */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 389 | if (dev->enabled) { |
| 390 | sb_config->GecConfig = 0; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 391 | } else { |
| 392 | sb_config->GecConfig = 1; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 393 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 394 | break; |
| 395 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 396 | case PCI_DEVFN(0x15, 0): /* 0:15:0 PCIe PortA */ |
Scott Duplichan | 8fed77a | 2011-06-18 10:46:45 -0500 | [diff] [blame] | 397 | { |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 398 | struct device *device; |
Paul Menzel | e4a016f | 2013-03-01 13:05:04 +0100 | [diff] [blame] | 399 | for (device = dev; device; device = device->sibling) { |
| 400 | if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break; |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 401 | sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled; |
| 402 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 403 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 404 | /* |
| 405 | * GPP_CFGMODE_X4000: PortA Lanes[3:0] |
| 406 | * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2] |
| 407 | * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3 |
| 408 | * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3 |
| 409 | */ |
| 410 | sb_config->GppLinkConfig = sb_chip->gpp_configuration; |
Scott Duplichan | 8fed77a | 2011-06-18 10:46:45 -0500 | [diff] [blame] | 411 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 412 | break; |
| 413 | |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 414 | case PCI_DEVFN(0x12, 0): /* 0:12:0 OHCI-USB1 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 415 | sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled; |
| 416 | break; |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 417 | case PCI_DEVFN(0x12, 2): /* 0:12:2 EHCI-USB1 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 418 | sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled; |
| 419 | break; |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 420 | case PCI_DEVFN(0x13, 0): /* 0:13:0 OHCI-USB2 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 421 | sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled; |
| 422 | break; |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 423 | case PCI_DEVFN(0x13, 2): /* 0:13:2 EHCI-USB2 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 424 | sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled; |
| 425 | break; |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 426 | case PCI_DEVFN(0x14, 5): /* 0:14:5 OHCI-USB4 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 427 | sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled; |
| 428 | break; |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 429 | case PCI_DEVFN(0x16, 0): /* 0:16:0 OHCI-USB3 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 430 | sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled; |
| 431 | break; |
Kyösti Mälkki | dda0fc4 | 2018-05-20 14:17:19 +0300 | [diff] [blame] | 432 | case PCI_DEVFN(0x16, 2): /* 0:16:2 EHCI-USB3 */ |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 433 | sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled; |
| 434 | |
Kyösti Mälkki | 9de8ab9 | 2017-09-09 16:51:34 +0300 | [diff] [blame] | 435 | /* FIXME: Find better callsites for these. |
| 436 | * call the CIMX entry at the last sb800 device, |
Kerry Sheh | 75df106 | 2011-10-10 19:19:46 +0800 | [diff] [blame] | 437 | * so make sure the mainboard devicetree is complete |
| 438 | */ |
Kyösti Mälkki | c551caa | 2014-06-20 12:31:23 +0300 | [diff] [blame] | 439 | if (!acpi_is_wakeup_s3()) |
zbao | 9bcdbf8 | 2012-04-05 13:18:49 +0800 | [diff] [blame] | 440 | sb_Before_Pci_Init(); |
| 441 | else |
| 442 | sb_Before_Pci_Restore_Init(); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 443 | break; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 444 | |
| 445 | default: |
| 446 | break; |
| 447 | } |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 448 | } |
| 449 | |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 450 | struct chip_operations southbridge_amd_cimx_sb800_ops = { |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 451 | CHIP_NAME("ATI SB800") |
Kyösti Mälkki | 41cd047 | 2015-02-07 11:20:54 +0200 | [diff] [blame] | 452 | .init = sb800_init, |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 453 | .enable_dev = sb800_enable, |
| 454 | }; |