blob: b0ee037ae2f7929cef541cbdfb8b857b96487bf8 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Frank Vibrans63e62b02011-02-14 18:38:14 +00003
Michał Żygowski287ce5f2019-12-01 17:41:23 +01004#include <amdblocks/acpimmio.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +02006#include <device/device.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +00007#include <device/pci.h> /* device_operations */
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02008#include <device/pci_ops.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +00009#include <device/pci_ids.h>
Mike Loptienc93a75a2014-06-06 15:16:29 -060010#include <bootstate.h>
Kerry She991f8802011-06-01 01:56:49 +000011#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000012#include <device/smbus.h> /* smbus_bus_operations */
zbao366f0fc2012-08-03 16:58:53 +080013#include <pc80/mc146818rtc.h>
Edward O'Callaghane61dd0f2014-05-06 23:53:09 +100014#include <pc80/i8254.h>
15#include <pc80/i8259.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000016#include <console/console.h> /* printk */
Furquan Shaikh76cedd22020-05-02 10:24:23 -070017#include <acpi/acpi.h>
Kyösti Mälkkie2227a22014-02-05 13:02:55 +020018#include <device/pci_ehci.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000019#include "lpc.h" /* lpc_read_resources */
Elyes HAOUASb0f19882018-06-09 11:59:00 +020020#include "SBPLATFORM.h" /* Platform Specific Definitions */
Frank Vibrans63e62b02011-02-14 18:38:14 +000021#include "cfg.h" /* sb800 Cimx configuration */
efdesign9805a89ab2011-06-20 17:38:49 -070022#include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
Kerry Shefeed3292011-08-18 18:03:44 +080023#include "sb_cimx.h" /* AMD CIMX wrapper entries */
Dave Frodin23023a52012-11-13 07:09:12 -070024#include "smbus.h"
Martin Rothe899e512012-12-05 16:07:11 -070025#include "fan.h"
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +010026#include "pci_devs.h"
Stefan Reinauer13e41822015-04-27 14:02:36 -070027#include <southbridge/amd/common/amd_pci_util.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000028
Frank Vibrans63e62b02011-02-14 18:38:14 +000029static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config
30static AMDSBCFG *sb_config = &sb_late_cfg;
31
Frank Vibrans63e62b02011-02-14 18:38:14 +000032/**
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 Roth6355cbf2015-01-04 15:22:26 -070039 * @param[in] config Southbridge configuration structure pointer.
Frank Vibrans63e62b02011-02-14 18:38:14 +000040 *
41 */
Elyes HAOUAS251279c2018-07-08 12:41:56 +020042static u32 sb800_callout_entry(u32 func, u32 data, void *config)
Frank Vibrans63e62b02011-02-14 18:38:14 +000043{
44 u32 ret = 0;
Kerry Shefeed3292011-08-18 18:03:44 +080045 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
Frank Vibrans63e62b02011-02-14 18:38:14 +000046 switch (func) {
47 case CB_SBGPP_RESET_ASSERT:
Frank Vibrans63e62b02011-02-14 18:38:14 +000048 break;
49
50 case CB_SBGPP_RESET_DEASSERT:
Frank Vibrans63e62b02011-02-14 18:38:14 +000051 break;
52
53 case IMC_FIRMWARE_FAIL:
54 break;
55
56 default:
57 break;
58 }
59
Kerry Shefeed3292011-08-18 18:03:44 +080060 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
Frank Vibrans63e62b02011-02-14 18:38:14 +000061 return ret;
62}
63
Kerry Sheh0e6344e2011-10-12 11:42:59 +080064#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 */
70static void ahci_raid_init(struct device *dev)
71{
72 u8 irq = 0;
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070073 void *bar5;
74 u32 caps, ports, val;
Kerry Sheh0e6344e2011-10-12 11:42:59 +080075
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 Reinauer12bce3f2015-06-18 01:17:38 -070087 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 Sheh0e6344e2011-10-12 11:42:59 +080089
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070090 caps = read32(bar5 + HOST_CAP);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080091 caps = (caps & 0x1F) + 1;
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070092 ports= read32(bar5 + HOST_PORTS_IMPL);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080093 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 Reinauer12bce3f2015-06-18 01:17:38 -070096 val = read32(bar5 + HOST_CTL);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080097 if (!(val & HOST_CTL_AHCI_EN)) {
Stefan Reinauer12bce3f2015-06-18 01:17:38 -070098 write32(bar5 + HOST_CTL, val | HOST_CTL_AHCI_EN);
Kerry Sheh0e6344e2011-10-12 11:42:59 +080099 }
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 Vibrans63e62b02011-02-14 18:38:14 +0000105
106static struct pci_operations lops_pci = {
Kerry Shefeed3292011-08-18 18:03:44 +0800107 .set_subsystem = pci_dev_set_subsystem,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000108};
109
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200110static void lpc_init(struct device *dev)
zbao366f0fc2012-08-03 16:58:53 +0800111{
112 printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - Start.\n");
113
Gabe Black03abaee212014-04-30 21:31:44 -0700114 cmos_check_update_date();
zbao366f0fc2012-08-03 16:58:53 +0800115
Mike Loptienac529b12013-02-22 13:18:31 -0700116 /* Initialize the real time clock.
Gabe Blackb3f08c62014-04-30 17:12:25 -0700117 * The 0 argument tells cmos_init not to
Mike Loptienac529b12013-02-22 13:18:31 -0700118 * update CMOS unless it is invalid.
Gabe Blackb3f08c62014-04-30 17:12:25 -0700119 * 1 tells cmos_init to always initialize the CMOS.
Mike Loptienac529b12013-02-22 13:18:31 -0700120 */
Gabe Blackb3f08c62014-04-30 17:12:25 -0700121 cmos_init(0);
Mike Loptienac529b12013-02-22 13:18:31 -0700122
Edward O'Callaghane61dd0f2014-05-06 23:53:09 +1000123 setup_i8259(); /* Initialize i8259 pic */
124 setup_i8254(); /* Initialize i8254 timers */
125
zbao366f0fc2012-08-03 16:58:53 +0800126 printk(BIOS_DEBUG, "SB800 - Late.c - lpc_init - End.\n");
127}
128
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200129unsigned long acpi_fill_mcfg(unsigned long current)
130{
131 /* Just a dummy */
132 return current;
133}
134
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600135static const char *lpc_acpi_name(const struct device *dev)
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100136{
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 Vibrans63e62b02011-02-14 18:38:14 +0000149static struct device_operations lpc_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200150 .read_resources = lpc_read_resources,
151 .set_resources = lpc_set_resources,
152 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800153#if CONFIG(HAVE_ACPI_TABLES)
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200154 .write_acpi_tables = acpi_write_hpet,
155#endif
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200156 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100157 .scan_bus = scan_static_bus,
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200158 .ops_pci = &lops_pci,
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100159 .acpi_name = lpc_acpi_name,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000160};
161
162static const struct pci_driver lpc_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200163 .ops = &lpc_ops,
164 .vendor = PCI_VENDOR_ID_ATI,
165 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000166};
167
Frank Vibrans63e62b02011-02-14 18:38:14 +0000168static struct device_operations sata_ops = {
169 .read_resources = pci_dev_read_resources,
170 .set_resources = pci_dev_set_resources,
Kerry Shefeed3292011-08-18 18:03:44 +0800171 .enable_resources = pci_dev_enable_resources,
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800172 .init = ahci_raid_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000173 .ops_pci = &lops_pci,
174};
175
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800176static const struct pci_driver ahci_driver __pci_driver = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000177 .ops = &sata_ops,
178 .vendor = PCI_VENDOR_ID_ATI,
Scott Duplichanf191c722011-05-15 21:38:08 +0000179 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000180};
181
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800182static 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};
187static 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 Vibrans63e62b02011-02-14 18:38:14 +0000193static struct device_operations usb_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300194 .read_resources = pci_ehci_read_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000195 .set_resources = pci_dev_set_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000196 .enable_resources = pci_dev_enable_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000197 .ops_pci = &lops_pci,
198};
199
200/*
Elyes HAOUAS44f558e2020-02-24 13:26:04 +0100201 * The pci id of USB ctrl 0 and 1 are the same.
Frank Vibrans63e62b02011-02-14 18:38:14 +0000202 */
203static 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
209static 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
215static 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 Vibrans63e62b02011-02-14 18:38:14 +0000222static struct device_operations azalia_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200223 .read_resources = pci_dev_read_resources,
224 .set_resources = pci_dev_set_resources,
225 .enable_resources = pci_dev_enable_resources,
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200226 .ops_pci = &lops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000227};
228
229static const struct pci_driver azalia_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200230 .ops = &azalia_ops,
231 .vendor = PCI_VENDOR_ID_ATI,
232 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000233};
234
235
Frank Vibrans63e62b02011-02-14 18:38:14 +0000236static struct device_operations gec_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200237 .read_resources = pci_dev_read_resources,
238 .set_resources = pci_dev_set_resources,
239 .enable_resources = pci_dev_enable_resources,
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200240 .ops_pci = &lops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000241};
242
243static const struct pci_driver gec_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200244 .ops = &gec_ops,
245 .vendor = PCI_VENDOR_ID_ATI,
246 .device = PCI_DEVICE_ID_ATI_SB800_GEC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000247};
248
Kerry She3e706b62011-06-24 22:52:15 +0800249/**
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200250 * Fill build time defaults.
251 */
252static void sb800_init(void *chip_info)
253{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200254 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200255 sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry;
256 sb800_cimx_config(sb_config);
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200257
Paul Menzel114a9482015-10-25 22:27:42 +0100258 /* Initially enable all GPP ports 0 to 3 */
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200259 abcfg_reg(0xc0, 0x01FF, 0x0F4);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200260}
261
262/**
Kerry Shefeed3292011-08-18 18:03:44 +0800263 * South Bridge CIMx ramstage entry point wrapper.
264 */
265void sb_Before_Pci_Init(void)
266{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200267 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800268 sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
269 AmdSbDispatcher(sb_config);
270}
271
272void sb_After_Pci_Init(void)
273{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200274 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800275 sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
276 AmdSbDispatcher(sb_config);
277}
278
279void sb_Mid_Post_Init(void)
280{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200281 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800282 sb_config->StdHeader.Func = SB_MID_POST_INIT;
283 AmdSbDispatcher(sb_config);
284}
285
286void sb_Late_Post(void)
287{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200288 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800289 sb_config->StdHeader.Func = SB_LATE_POST_INIT;
290 AmdSbDispatcher(sb_config);
291}
292
zbao9bcdbf82012-04-05 13:18:49 +0800293void sb_Before_Pci_Restore_Init(void)
294{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200295 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800296 sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT;
297 AmdSbDispatcher(sb_config);
298}
299
300void sb_After_Pci_Restore_Init(void)
301{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200302 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800303 sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT;
304 AmdSbDispatcher(sb_config);
305}
Kerry Shefeed3292011-08-18 18:03:44 +0800306
Mike Loptienc93a75a2014-06-06 15:16:29 -0600307/*
308 * Update the PCI devices with a valid IRQ number
309 * that is set in the mainboard PCI_IRQ structures.
310 */
311static 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 Durbin9ef9d852015-03-16 17:30:09 -0500324BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);
Mike Loptienc93a75a2014-06-06 15:16:29 -0600325
Kerry Shefeed3292011-08-18 18:03:44 +0800326/**
Frank Vibrans63e62b02011-02-14 18:38:14 +0000327 * @brief SB Cimx entry point sbBeforePciInit wrapper
328 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200329static void sb800_enable(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000330{
efdesign9805a89ab2011-06-20 17:38:49 -0700331 struct southbridge_amd_cimx_sb800_config *sb_chip =
332 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000333
Frank Vibrans63e62b02011-02-14 18:38:14 +0000334 switch (dev->path.pci.devfn) {
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300335 case PCI_DEVFN(0x11, 0): /* 0:11.0 SATA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000336 if (dev->enabled) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200337 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100338 if (sb_chip->boot_switch_sata_ide == 1)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000339 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100340 else if (sb_chip->boot_switch_sata_ide == 0)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000341 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
342 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200343 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000344 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000345 break;
346
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300347 case PCI_DEVFN(0x14, 0): /* 0:14:0 SMBUS */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800348 clear_ioapic(VIO_APIC_VADDR);
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300349 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800350 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000351 break;
352
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300353 case PCI_DEVFN(0x14, 1): /* 0:14:1 IDE */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000354 break;
355
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300356 case PCI_DEVFN(0x14, 2): /* 0:14:2 HDA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000357 if (dev->enabled) {
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100358 if (sb_config->AzaliaController == AZALIA_DISABLE) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200359 sb_config->AzaliaController = AZALIA_AUTO;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000360 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000361 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200362 sb_config->AzaliaController = AZALIA_DISABLE;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000363 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000364 break;
365
366
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300367 case PCI_DEVFN(0x14, 3): /* 0:14:3 LPC */
Martin Rothe899e512012-12-05 16:07:11 -0700368 /* Initialize the fans */
Julius Wernercd49cce2019-03-05 16:53:33 -0800369#if CONFIG(SB800_IMC_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700370 init_sb800_IMC_fans(dev);
Julius Wernercd49cce2019-03-05 16:53:33 -0800371#elif CONFIG(SB800_MANUAL_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700372 init_sb800_MANUAL_fans(dev);
373#endif
Frank Vibrans63e62b02011-02-14 18:38:14 +0000374 break;
375
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300376 case PCI_DEVFN(0x14, 4): /* 0:14:4 PCI */
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200377 /* 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älkki0b87bb72014-11-11 17:22:23 +0200382 if (!sb_chip->disconnect_pcib && dev->enabled)
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100383 pm_write8(0xea, pm_read8(0xea) & 0xfe);
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200384 else
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100385 pm_write8(0xea, (pm_read8(0xea) & 0xfe) | 1);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000386 break;
387
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300388 case PCI_DEVFN(0x14, 6): /* 0:14:6 GEC */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000389 if (dev->enabled) {
390 sb_config->GecConfig = 0;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000391 } else {
392 sb_config->GecConfig = 1;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000393 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000394 break;
395
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300396 case PCI_DEVFN(0x15, 0): /* 0:15:0 PCIe PortA */
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500397 {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200398 struct device *device;
Paul Menzele4a016f2013-03-01 13:05:04 +0100399 for (device = dev; device; device = device->sibling) {
400 if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break;
Kerry Shefeed3292011-08-18 18:03:44 +0800401 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
402 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000403
Kerry Shefeed3292011-08-18 18:03:44 +0800404 /*
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 Duplichan8fed77a2011-06-18 10:46:45 -0500411 }
Kerry Shefeed3292011-08-18 18:03:44 +0800412 break;
413
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300414 case PCI_DEVFN(0x12, 0): /* 0:12:0 OHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800415 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
416 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300417 case PCI_DEVFN(0x12, 2): /* 0:12:2 EHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800418 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
419 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300420 case PCI_DEVFN(0x13, 0): /* 0:13:0 OHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800421 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
422 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300423 case PCI_DEVFN(0x13, 2): /* 0:13:2 EHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800424 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
425 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300426 case PCI_DEVFN(0x14, 5): /* 0:14:5 OHCI-USB4 */
Kerry Shefeed3292011-08-18 18:03:44 +0800427 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
428 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300429 case PCI_DEVFN(0x16, 0): /* 0:16:0 OHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800430 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
431 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300432 case PCI_DEVFN(0x16, 2): /* 0:16:2 EHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800433 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
434
Kyösti Mälkki9de8ab92017-09-09 16:51:34 +0300435 /* FIXME: Find better callsites for these.
436 * call the CIMX entry at the last sb800 device,
Kerry Sheh75df1062011-10-10 19:19:46 +0800437 * so make sure the mainboard devicetree is complete
438 */
Kyösti Mälkkic551caa2014-06-20 12:31:23 +0300439 if (!acpi_is_wakeup_s3())
zbao9bcdbf82012-04-05 13:18:49 +0800440 sb_Before_Pci_Init();
441 else
442 sb_Before_Pci_Restore_Init();
Kerry Shefeed3292011-08-18 18:03:44 +0800443 break;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000444
445 default:
446 break;
447 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000448}
449
efdesign9805a89ab2011-06-20 17:38:49 -0700450struct chip_operations southbridge_amd_cimx_sb800_ops = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000451 CHIP_NAME("ATI SB800")
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200452 .init = sb800_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000453 .enable_dev = sb800_enable,
454};