blob: b6cc3c777b5f5888f6c239807a44a1adb2de4ef9 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Frank Vibrans63e62b02011-02-14 18:38:14 +00002
Michał Żygowski287ce5f2019-12-01 17:41:23 +01003#include <amdblocks/acpimmio.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +02005#include <device/device.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +00006#include <device/pci.h> /* device_operations */
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +00008#include <device/pci_ids.h>
Mike Loptienc93a75a2014-06-06 15:16:29 -06009#include <bootstate.h>
Kerry She991f8802011-06-01 01:56:49 +000010#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000011#include <device/smbus.h> /* smbus_bus_operations */
zbao366f0fc2012-08-03 16:58:53 +080012#include <pc80/mc146818rtc.h>
Edward O'Callaghane61dd0f2014-05-06 23:53:09 +100013#include <pc80/i8254.h>
14#include <pc80/i8259.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000015#include <console/console.h> /* printk */
Furquan Shaikh76cedd22020-05-02 10:24:23 -070016#include <acpi/acpi.h>
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020017#include <device/pci_ehci.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000018#include "lpc.h" /* lpc_read_resources */
Elyes HAOUASb0f19882018-06-09 11:59:00 +020019#include "SBPLATFORM.h" /* Platform Specific Definitions */
Frank Vibrans63e62b02011-02-14 18:38:14 +000020#include "cfg.h" /* sb800 Cimx configuration */
efdesign9805a89ab2011-06-20 17:38:49 -070021#include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
Kerry Shefeed3292011-08-18 18:03:44 +080022#include "sb_cimx.h" /* AMD CIMX wrapper entries */
Dave Frodin23023a52012-11-13 07:09:12 -070023#include "smbus.h"
Martin Rothe899e512012-12-05 16:07:11 -070024#include "fan.h"
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +010025#include "pci_devs.h"
Stefan Reinauer13e41822015-04-27 14:02:36 -070026#include <southbridge/amd/common/amd_pci_util.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000027
Frank Vibrans63e62b02011-02-14 18:38:14 +000028static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config
29static AMDSBCFG *sb_config = &sb_late_cfg;
30
Frank Vibrans63e62b02011-02-14 18:38:14 +000031/**
32 * @brief Entry point of Southbridge CIMx callout
33 *
34 * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
35 *
36 * @param[in] func Southbridge CIMx Function ID.
37 * @param[in] data Southbridge Input Data.
Martin Roth6355cbf2015-01-04 15:22:26 -070038 * @param[in] config Southbridge configuration structure pointer.
Frank Vibrans63e62b02011-02-14 18:38:14 +000039 *
40 */
Elyes HAOUAS251279c2018-07-08 12:41:56 +020041static u32 sb800_callout_entry(u32 func, u32 data, void *config)
Frank Vibrans63e62b02011-02-14 18:38:14 +000042{
43 u32 ret = 0;
Kerry Shefeed3292011-08-18 18:03:44 +080044 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
Frank Vibrans63e62b02011-02-14 18:38:14 +000045 switch (func) {
46 case CB_SBGPP_RESET_ASSERT:
Frank Vibrans63e62b02011-02-14 18:38:14 +000047 break;
48
49 case CB_SBGPP_RESET_DEASSERT:
Frank Vibrans63e62b02011-02-14 18:38:14 +000050 break;
51
52 case IMC_FIRMWARE_FAIL:
53 break;
54
55 default:
56 break;
57 }
58
Kerry Shefeed3292011-08-18 18:03:44 +080059 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
Frank Vibrans63e62b02011-02-14 18:38:14 +000060 return ret;
61}
62
Kerry Sheh0e6344e2011-10-12 11:42:59 +080063#define HOST_CAP 0x00 /* host capabilities */
64#define HOST_CTL 0x04 /* global host control */
65#define HOST_IRQ_STAT 0x08 /* interrupt status */
66#define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */
67
68#define HOST_CTL_AHCI_EN (1 << 31) /* AHCI enabled */
69static void ahci_raid_init(struct device *dev)
70{
71 u8 irq = 0;
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070072 void *bar5;
73 u32 caps, ports, val;
Kerry Sheh0e6344e2011-10-12 11:42:59 +080074
75 val = pci_read_config16(dev, PCI_CLASS_DEVICE);
76 if (val == PCI_CLASS_STORAGE_SATA) {
77 printk(BIOS_DEBUG, "AHCI controller ");
78 } else if (val == PCI_CLASS_STORAGE_RAID) {
79 printk(BIOS_DEBUG, "RAID controller ");
80 } else {
81 printk(BIOS_WARNING, "device class:%x, neither in ahci or raid mode\n", val);
82 return;
83 }
84
85 irq = pci_read_config8(dev, PCI_INTERRUPT_LINE);
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070086 bar5 = (void *)(uintptr_t)pci_read_config32(dev, PCI_BASE_ADDRESS_5);
87 printk(BIOS_DEBUG, "IOMEM base: %p, IRQ: 0x%X\n", bar5, irq);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080088
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070089 caps = read32(bar5 + HOST_CAP);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080090 caps = (caps & 0x1F) + 1;
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070091 ports= read32(bar5 + HOST_PORTS_IMPL);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080092 printk(BIOS_DEBUG, "Number of Ports: 0x%x, Port implemented(bit map): 0x%x\n", caps, ports);
93
94 /* make sure ahci is enabled */
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070095 val = read32(bar5 + HOST_CTL);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080096 if (!(val & HOST_CTL_AHCI_EN)) {
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070097 write32(bar5 + HOST_CTL, val | HOST_CTL_AHCI_EN);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080098 }
99
100 dev->command |= PCI_COMMAND_MASTER;
Nico Hubere9e13d42020-06-07 15:54:32 +0000101 pci_write_config8(dev, PCI_COMMAND, dev->command);
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800102 printk(BIOS_DEBUG, "AHCI/RAID controller initialized\n");
103}
Frank Vibrans63e62b02011-02-14 18:38:14 +0000104
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200105static void lpc_init(struct device *dev)
zbao366f0fc2012-08-03 16:58:53 +0800106{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100107 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
zbao366f0fc2012-08-03 16:58:53 +0800108
Gabe Black03abaee212014-04-30 21:31:44 -0700109 cmos_check_update_date();
zbao366f0fc2012-08-03 16:58:53 +0800110
Mike Loptienac529b12013-02-22 13:18:31 -0700111 /* Initialize the real time clock.
Gabe Blackb3f08c62014-04-30 17:12:25 -0700112 * The 0 argument tells cmos_init not to
Mike Loptienac529b12013-02-22 13:18:31 -0700113 * update CMOS unless it is invalid.
Gabe Blackb3f08c62014-04-30 17:12:25 -0700114 * 1 tells cmos_init to always initialize the CMOS.
Mike Loptienac529b12013-02-22 13:18:31 -0700115 */
Gabe Blackb3f08c62014-04-30 17:12:25 -0700116 cmos_init(0);
Mike Loptienac529b12013-02-22 13:18:31 -0700117
Edward O'Callaghane61dd0f2014-05-06 23:53:09 +1000118 setup_i8259(); /* Initialize i8259 pic */
119 setup_i8254(); /* Initialize i8254 timers */
120
Elyes HAOUASbfc255a2020-03-07 13:05:14 +0100121 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
zbao366f0fc2012-08-03 16:58:53 +0800122}
123
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200124unsigned long acpi_fill_mcfg(unsigned long current)
125{
Angel Pons12d31b22021-06-16 12:39:23 +0200126 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
127 CONFIG_MMCONF_BASE_ADDRESS, 0, 0, CONFIG_MMCONF_BUS_NUMBER - 1);
128
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200129 return current;
130}
131
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600132static const char *lpc_acpi_name(const struct device *dev)
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100133{
134 if (dev->path.type != DEVICE_PATH_PCI)
135 return NULL;
136
137 switch (dev->path.pci.devfn) {
138 /* DSDT: acpi/lpc.asl */
139 case LPC_DEVFN:
140 return "LIBR";
141 }
142
143 return NULL;
144}
145
Frank Vibrans63e62b02011-02-14 18:38:14 +0000146static struct device_operations lpc_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200147 .read_resources = lpc_read_resources,
148 .set_resources = lpc_set_resources,
149 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800150#if CONFIG(HAVE_ACPI_TABLES)
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200151 .write_acpi_tables = acpi_write_hpet,
152#endif
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200153 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100154 .scan_bus = scan_static_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200155 .ops_pci = &pci_dev_ops_pci,
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100156 .acpi_name = lpc_acpi_name,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000157};
158
159static const struct pci_driver lpc_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200160 .ops = &lpc_ops,
161 .vendor = PCI_VENDOR_ID_ATI,
162 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000163};
164
Frank Vibrans63e62b02011-02-14 18:38:14 +0000165static struct device_operations sata_ops = {
166 .read_resources = pci_dev_read_resources,
167 .set_resources = pci_dev_set_resources,
Kerry Shefeed3292011-08-18 18:03:44 +0800168 .enable_resources = pci_dev_enable_resources,
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800169 .init = ahci_raid_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200170 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000171};
172
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800173static const struct pci_driver ahci_driver __pci_driver = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000174 .ops = &sata_ops,
175 .vendor = PCI_VENDOR_ID_ATI,
Scott Duplichanf191c722011-05-15 21:38:08 +0000176 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000177};
178
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800179static const struct pci_driver raid_driver __pci_driver = {
180 .ops = &sata_ops,
181 .vendor = PCI_VENDOR_ID_ATI,
182 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID,
183};
184static const struct pci_driver raid5_driver __pci_driver = {
185 .ops = &sata_ops,
186 .vendor = PCI_VENDOR_ID_ATI,
187 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5,
188};
189
Frank Vibrans63e62b02011-02-14 18:38:14 +0000190static struct device_operations usb_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300191 .read_resources = pci_ehci_read_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000192 .set_resources = pci_dev_set_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000193 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200194 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000195};
196
197/*
Elyes HAOUAS44f558e2020-02-24 13:26:04 +0100198 * The pci id of USB ctrl 0 and 1 are the same.
Frank Vibrans63e62b02011-02-14 18:38:14 +0000199 */
200static const struct pci_driver usb_ohci123_driver __pci_driver = {
201 .ops = &usb_ops,
202 .vendor = PCI_VENDOR_ID_ATI,
203 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
204};
205
206static const struct pci_driver usb_ehci123_driver __pci_driver = {
207 .ops = &usb_ops,
208 .vendor = PCI_VENDOR_ID_ATI,
209 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
210};
211
212static const struct pci_driver usb_ohci4_driver __pci_driver = {
213 .ops = &usb_ops,
214 .vendor = PCI_VENDOR_ID_ATI,
215 .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
216};
217
Frank Vibrans63e62b02011-02-14 18:38:14 +0000218static struct device_operations azalia_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200219 .read_resources = pci_dev_read_resources,
220 .set_resources = pci_dev_set_resources,
221 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200222 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000223};
224
225static const struct pci_driver azalia_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200226 .ops = &azalia_ops,
227 .vendor = PCI_VENDOR_ID_ATI,
228 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000229};
230
Frank Vibrans63e62b02011-02-14 18:38:14 +0000231static struct device_operations gec_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200232 .read_resources = pci_dev_read_resources,
233 .set_resources = pci_dev_set_resources,
234 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200235 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000236};
237
238static const struct pci_driver gec_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200239 .ops = &gec_ops,
240 .vendor = PCI_VENDOR_ID_ATI,
241 .device = PCI_DEVICE_ID_ATI_SB800_GEC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000242};
243
Kerry She3e706b62011-06-24 22:52:15 +0800244/**
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200245 * Fill build time defaults.
246 */
247static void sb800_init(void *chip_info)
248{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200249 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200250 sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry;
251 sb800_cimx_config(sb_config);
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200252
Paul Menzel114a9482015-10-25 22:27:42 +0100253 /* Initially enable all GPP ports 0 to 3 */
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200254 abcfg_reg(0xc0, 0x01FF, 0x0F4);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200255}
256
257/**
Kerry Shefeed3292011-08-18 18:03:44 +0800258 * South Bridge CIMx ramstage entry point wrapper.
259 */
260void sb_Before_Pci_Init(void)
261{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200262 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800263 sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
264 AmdSbDispatcher(sb_config);
265}
266
267void sb_After_Pci_Init(void)
268{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200269 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800270 sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
271 AmdSbDispatcher(sb_config);
272}
273
274void sb_Mid_Post_Init(void)
275{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200276 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800277 sb_config->StdHeader.Func = SB_MID_POST_INIT;
278 AmdSbDispatcher(sb_config);
279}
280
281void sb_Late_Post(void)
282{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200283 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800284 sb_config->StdHeader.Func = SB_LATE_POST_INIT;
285 AmdSbDispatcher(sb_config);
286}
287
zbao9bcdbf82012-04-05 13:18:49 +0800288void sb_Before_Pci_Restore_Init(void)
289{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200290 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800291 sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT;
292 AmdSbDispatcher(sb_config);
293}
294
295void sb_After_Pci_Restore_Init(void)
296{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200297 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800298 sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT;
299 AmdSbDispatcher(sb_config);
300}
Kerry Shefeed3292011-08-18 18:03:44 +0800301
Mike Loptienc93a75a2014-06-06 15:16:29 -0600302/*
303 * Update the PCI devices with a valid IRQ number
304 * that is set in the mainboard PCI_IRQ structures.
305 */
306static void set_pci_irqs(void *unused)
307{
308 /* Write PCI_INTR regs 0xC00/0xC01 */
309 write_pci_int_table();
310
311 /* Write IRQs for all devicetree enabled devices */
312 write_pci_cfg_irqs();
313}
314
315/*
316 * Hook this function into the PCI state machine
317 * on entry into BS_DEV_ENABLE.
318 */
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500319BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);
Mike Loptienc93a75a2014-06-06 15:16:29 -0600320
Kerry Shefeed3292011-08-18 18:03:44 +0800321/**
Frank Vibrans63e62b02011-02-14 18:38:14 +0000322 * @brief SB Cimx entry point sbBeforePciInit wrapper
323 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200324static void sb800_enable(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000325{
efdesign9805a89ab2011-06-20 17:38:49 -0700326 struct southbridge_amd_cimx_sb800_config *sb_chip =
327 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000328
Frank Vibrans63e62b02011-02-14 18:38:14 +0000329 switch (dev->path.pci.devfn) {
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300330 case PCI_DEVFN(0x11, 0): /* 0:11.0 SATA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000331 if (dev->enabled) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200332 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100333 if (sb_chip->boot_switch_sata_ide == 1)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000334 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100335 else if (sb_chip->boot_switch_sata_ide == 0)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000336 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
337 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200338 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000339 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000340 break;
341
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300342 case PCI_DEVFN(0x14, 0): /* 0:14:0 SMBUS */
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300343 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800344 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000345 break;
346
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300347 case PCI_DEVFN(0x14, 1): /* 0:14:1 IDE */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000348 break;
349
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300350 case PCI_DEVFN(0x14, 2): /* 0:14:2 HDA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000351 if (dev->enabled) {
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100352 if (sb_config->AzaliaController == AZALIA_DISABLE) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200353 sb_config->AzaliaController = AZALIA_AUTO;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000354 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000355 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200356 sb_config->AzaliaController = AZALIA_DISABLE;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000357 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000358 break;
359
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300360 case PCI_DEVFN(0x14, 3): /* 0:14:3 LPC */
Martin Rothe899e512012-12-05 16:07:11 -0700361 /* Initialize the fans */
Julius Wernercd49cce2019-03-05 16:53:33 -0800362#if CONFIG(SB800_IMC_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700363 init_sb800_IMC_fans(dev);
Julius Wernercd49cce2019-03-05 16:53:33 -0800364#elif CONFIG(SB800_MANUAL_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700365 init_sb800_MANUAL_fans(dev);
366#endif
Frank Vibrans63e62b02011-02-14 18:38:14 +0000367 break;
368
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300369 case PCI_DEVFN(0x14, 4): /* 0:14:4 PCI */
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200370 /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
371 * 'PCIDisable' set to 0 to enable P2P bridge.
372 * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
373 * to function as GPIO {GPIO 35:0}.
374 */
Kyösti Mälkki0b87bb72014-11-11 17:22:23 +0200375 if (!sb_chip->disconnect_pcib && dev->enabled)
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100376 pm_write8(0xea, pm_read8(0xea) & 0xfe);
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200377 else
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100378 pm_write8(0xea, (pm_read8(0xea) & 0xfe) | 1);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000379 break;
380
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300381 case PCI_DEVFN(0x14, 6): /* 0:14:6 GEC */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000382 if (dev->enabled) {
383 sb_config->GecConfig = 0;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000384 } else {
385 sb_config->GecConfig = 1;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000386 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000387 break;
388
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300389 case PCI_DEVFN(0x15, 0): /* 0:15:0 PCIe PortA */
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500390 {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200391 struct device *device;
Paul Menzele4a016f2013-03-01 13:05:04 +0100392 for (device = dev; device; device = device->sibling) {
393 if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break;
Kerry Shefeed3292011-08-18 18:03:44 +0800394 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
395 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000396
Kerry Shefeed3292011-08-18 18:03:44 +0800397 /*
398 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
399 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
400 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
401 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
402 */
403 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500404 }
Kerry Shefeed3292011-08-18 18:03:44 +0800405 break;
406
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300407 case PCI_DEVFN(0x12, 0): /* 0:12:0 OHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800408 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
409 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300410 case PCI_DEVFN(0x12, 2): /* 0:12:2 EHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800411 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
412 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300413 case PCI_DEVFN(0x13, 0): /* 0:13:0 OHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800414 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
415 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300416 case PCI_DEVFN(0x13, 2): /* 0:13:2 EHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800417 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
418 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300419 case PCI_DEVFN(0x14, 5): /* 0:14:5 OHCI-USB4 */
Kerry Shefeed3292011-08-18 18:03:44 +0800420 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
421 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300422 case PCI_DEVFN(0x16, 0): /* 0:16:0 OHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800423 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
424 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300425 case PCI_DEVFN(0x16, 2): /* 0:16:2 EHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800426 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
427
Kyösti Mälkki9de8ab92017-09-09 16:51:34 +0300428 /* FIXME: Find better callsites for these.
429 * call the CIMX entry at the last sb800 device,
Kerry Sheh75df1062011-10-10 19:19:46 +0800430 * so make sure the mainboard devicetree is complete
431 */
Kyösti Mälkkic551caa2014-06-20 12:31:23 +0300432 if (!acpi_is_wakeup_s3())
zbao9bcdbf82012-04-05 13:18:49 +0800433 sb_Before_Pci_Init();
434 else
435 sb_Before_Pci_Restore_Init();
Kerry Shefeed3292011-08-18 18:03:44 +0800436 break;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000437
438 default:
439 break;
440 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000441}
442
efdesign9805a89ab2011-06-20 17:38:49 -0700443struct chip_operations southbridge_amd_cimx_sb800_ops = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000444 CHIP_NAME("ATI SB800")
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200445 .init = sb800_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000446 .enable_dev = sb800_enable,
447};