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