blob: d57ce006a31ee0a5f7dd7fffc6d4dce7018627da [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;
Elyes HAOUAS04506e22020-04-28 19:28:19 +0200101 pci_write_config16(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{
126 /* Just a dummy */
127 return current;
128}
129
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600130static const char *lpc_acpi_name(const struct device *dev)
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100131{
132 if (dev->path.type != DEVICE_PATH_PCI)
133 return NULL;
134
135 switch (dev->path.pci.devfn) {
136 /* DSDT: acpi/lpc.asl */
137 case LPC_DEVFN:
138 return "LIBR";
139 }
140
141 return NULL;
142}
143
Frank Vibrans63e62b02011-02-14 18:38:14 +0000144static struct device_operations lpc_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200145 .read_resources = lpc_read_resources,
146 .set_resources = lpc_set_resources,
147 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800148#if CONFIG(HAVE_ACPI_TABLES)
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200149 .write_acpi_tables = acpi_write_hpet,
150#endif
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200151 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100152 .scan_bus = scan_static_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200153 .ops_pci = &pci_dev_ops_pci,
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100154 .acpi_name = lpc_acpi_name,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000155};
156
157static const struct pci_driver lpc_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200158 .ops = &lpc_ops,
159 .vendor = PCI_VENDOR_ID_ATI,
160 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000161};
162
Frank Vibrans63e62b02011-02-14 18:38:14 +0000163static struct device_operations sata_ops = {
164 .read_resources = pci_dev_read_resources,
165 .set_resources = pci_dev_set_resources,
Kerry Shefeed3292011-08-18 18:03:44 +0800166 .enable_resources = pci_dev_enable_resources,
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800167 .init = ahci_raid_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200168 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000169};
170
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800171static const struct pci_driver ahci_driver __pci_driver = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000172 .ops = &sata_ops,
173 .vendor = PCI_VENDOR_ID_ATI,
Scott Duplichanf191c722011-05-15 21:38:08 +0000174 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000175};
176
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800177static const struct pci_driver raid_driver __pci_driver = {
178 .ops = &sata_ops,
179 .vendor = PCI_VENDOR_ID_ATI,
180 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID,
181};
182static const struct pci_driver raid5_driver __pci_driver = {
183 .ops = &sata_ops,
184 .vendor = PCI_VENDOR_ID_ATI,
185 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5,
186};
187
Frank Vibrans63e62b02011-02-14 18:38:14 +0000188static struct device_operations usb_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300189 .read_resources = pci_ehci_read_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000190 .set_resources = pci_dev_set_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000191 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200192 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000193};
194
195/*
Elyes HAOUAS44f558e2020-02-24 13:26:04 +0100196 * The pci id of USB ctrl 0 and 1 are the same.
Frank Vibrans63e62b02011-02-14 18:38:14 +0000197 */
198static const struct pci_driver usb_ohci123_driver __pci_driver = {
199 .ops = &usb_ops,
200 .vendor = PCI_VENDOR_ID_ATI,
201 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
202};
203
204static const struct pci_driver usb_ehci123_driver __pci_driver = {
205 .ops = &usb_ops,
206 .vendor = PCI_VENDOR_ID_ATI,
207 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
208};
209
210static const struct pci_driver usb_ohci4_driver __pci_driver = {
211 .ops = &usb_ops,
212 .vendor = PCI_VENDOR_ID_ATI,
213 .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
214};
215
216
Frank Vibrans63e62b02011-02-14 18:38:14 +0000217static struct device_operations azalia_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200218 .read_resources = pci_dev_read_resources,
219 .set_resources = pci_dev_set_resources,
220 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200221 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000222};
223
224static const struct pci_driver azalia_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200225 .ops = &azalia_ops,
226 .vendor = PCI_VENDOR_ID_ATI,
227 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000228};
229
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 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800343 clear_ioapic(VIO_APIC_VADDR);
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300344 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800345 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000346 break;
347
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300348 case PCI_DEVFN(0x14, 1): /* 0:14:1 IDE */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000349 break;
350
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300351 case PCI_DEVFN(0x14, 2): /* 0:14:2 HDA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000352 if (dev->enabled) {
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100353 if (sb_config->AzaliaController == AZALIA_DISABLE) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200354 sb_config->AzaliaController = AZALIA_AUTO;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000355 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000356 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200357 sb_config->AzaliaController = AZALIA_DISABLE;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000358 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000359 break;
360
361
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300362 case PCI_DEVFN(0x14, 3): /* 0:14:3 LPC */
Martin Rothe899e512012-12-05 16:07:11 -0700363 /* Initialize the fans */
Julius Wernercd49cce2019-03-05 16:53:33 -0800364#if CONFIG(SB800_IMC_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700365 init_sb800_IMC_fans(dev);
Julius Wernercd49cce2019-03-05 16:53:33 -0800366#elif CONFIG(SB800_MANUAL_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700367 init_sb800_MANUAL_fans(dev);
368#endif
Frank Vibrans63e62b02011-02-14 18:38:14 +0000369 break;
370
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300371 case PCI_DEVFN(0x14, 4): /* 0:14:4 PCI */
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200372 /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
373 * 'PCIDisable' set to 0 to enable P2P bridge.
374 * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
375 * to function as GPIO {GPIO 35:0}.
376 */
Kyösti Mälkki0b87bb72014-11-11 17:22:23 +0200377 if (!sb_chip->disconnect_pcib && dev->enabled)
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100378 pm_write8(0xea, pm_read8(0xea) & 0xfe);
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200379 else
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100380 pm_write8(0xea, (pm_read8(0xea) & 0xfe) | 1);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000381 break;
382
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300383 case PCI_DEVFN(0x14, 6): /* 0:14:6 GEC */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000384 if (dev->enabled) {
385 sb_config->GecConfig = 0;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000386 } else {
387 sb_config->GecConfig = 1;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000388 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000389 break;
390
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300391 case PCI_DEVFN(0x15, 0): /* 0:15:0 PCIe PortA */
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500392 {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200393 struct device *device;
Paul Menzele4a016f2013-03-01 13:05:04 +0100394 for (device = dev; device; device = device->sibling) {
395 if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break;
Kerry Shefeed3292011-08-18 18:03:44 +0800396 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
397 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000398
Kerry Shefeed3292011-08-18 18:03:44 +0800399 /*
400 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
401 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
402 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
403 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
404 */
405 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500406 }
Kerry Shefeed3292011-08-18 18:03:44 +0800407 break;
408
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300409 case PCI_DEVFN(0x12, 0): /* 0:12:0 OHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800410 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
411 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300412 case PCI_DEVFN(0x12, 2): /* 0:12:2 EHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800413 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
414 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300415 case PCI_DEVFN(0x13, 0): /* 0:13:0 OHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800416 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
417 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300418 case PCI_DEVFN(0x13, 2): /* 0:13:2 EHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800419 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
420 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300421 case PCI_DEVFN(0x14, 5): /* 0:14:5 OHCI-USB4 */
Kerry Shefeed3292011-08-18 18:03:44 +0800422 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
423 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300424 case PCI_DEVFN(0x16, 0): /* 0:16:0 OHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800425 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
426 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300427 case PCI_DEVFN(0x16, 2): /* 0:16:2 EHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800428 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
429
Kyösti Mälkki9de8ab92017-09-09 16:51:34 +0300430 /* FIXME: Find better callsites for these.
431 * call the CIMX entry at the last sb800 device,
Kerry Sheh75df1062011-10-10 19:19:46 +0800432 * so make sure the mainboard devicetree is complete
433 */
Kyösti Mälkkic551caa2014-06-20 12:31:23 +0300434 if (!acpi_is_wakeup_s3())
zbao9bcdbf82012-04-05 13:18:49 +0800435 sb_Before_Pci_Init();
436 else
437 sb_Before_Pci_Restore_Init();
Kerry Shefeed3292011-08-18 18:03:44 +0800438 break;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000439
440 default:
441 break;
442 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000443}
444
efdesign9805a89ab2011-06-20 17:38:49 -0700445struct chip_operations southbridge_amd_cimx_sb800_ops = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000446 CHIP_NAME("ATI SB800")
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200447 .init = sb800_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000448 .enable_dev = sb800_enable,
449};