blob: 4a5895b09bae6a5f4da9e664fc3ba6e7abb400eb [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
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600124static const char *lpc_acpi_name(const struct device *dev)
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100125{
126 if (dev->path.type != DEVICE_PATH_PCI)
127 return NULL;
128
129 switch (dev->path.pci.devfn) {
130 /* DSDT: acpi/lpc.asl */
131 case LPC_DEVFN:
132 return "LIBR";
133 }
134
135 return NULL;
136}
137
Frank Vibrans63e62b02011-02-14 18:38:14 +0000138static struct device_operations lpc_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200139 .read_resources = lpc_read_resources,
140 .set_resources = lpc_set_resources,
141 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800142#if CONFIG(HAVE_ACPI_TABLES)
Vladimir Serbinenko2a19fb12014-10-02 20:09:19 +0200143 .write_acpi_tables = acpi_write_hpet,
144#endif
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200145 .init = lpc_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100146 .scan_bus = scan_static_bus,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200147 .ops_pci = &pci_dev_ops_pci,
Tobias Diedrichd8a2c1f2017-02-20 02:46:19 +0100148 .acpi_name = lpc_acpi_name,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000149};
150
151static const struct pci_driver lpc_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200152 .ops = &lpc_ops,
153 .vendor = PCI_VENDOR_ID_ATI,
154 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000155};
156
Frank Vibrans63e62b02011-02-14 18:38:14 +0000157static struct device_operations sata_ops = {
158 .read_resources = pci_dev_read_resources,
159 .set_resources = pci_dev_set_resources,
Kerry Shefeed3292011-08-18 18:03:44 +0800160 .enable_resources = pci_dev_enable_resources,
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800161 .init = ahci_raid_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200162 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000163};
164
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800165static const struct pci_driver ahci_driver __pci_driver = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000166 .ops = &sata_ops,
167 .vendor = PCI_VENDOR_ID_ATI,
Scott Duplichanf191c722011-05-15 21:38:08 +0000168 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000169};
170
Kerry Sheh0e6344e2011-10-12 11:42:59 +0800171static const struct pci_driver raid_driver __pci_driver = {
172 .ops = &sata_ops,
173 .vendor = PCI_VENDOR_ID_ATI,
174 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID,
175};
176static const struct pci_driver raid5_driver __pci_driver = {
177 .ops = &sata_ops,
178 .vendor = PCI_VENDOR_ID_ATI,
179 .device = PCI_DEVICE_ID_ATI_SB800_SATA_RAID5,
180};
181
Frank Vibrans63e62b02011-02-14 18:38:14 +0000182static struct device_operations usb_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +0300183 .read_resources = pci_ehci_read_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000184 .set_resources = pci_dev_set_resources,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000185 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200186 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000187};
188
189/*
Elyes HAOUAS44f558e2020-02-24 13:26:04 +0100190 * The pci id of USB ctrl 0 and 1 are the same.
Frank Vibrans63e62b02011-02-14 18:38:14 +0000191 */
192static const struct pci_driver usb_ohci123_driver __pci_driver = {
193 .ops = &usb_ops,
194 .vendor = PCI_VENDOR_ID_ATI,
195 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
196};
197
198static const struct pci_driver usb_ehci123_driver __pci_driver = {
199 .ops = &usb_ops,
200 .vendor = PCI_VENDOR_ID_ATI,
201 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
202};
203
204static const struct pci_driver usb_ohci4_driver __pci_driver = {
205 .ops = &usb_ops,
206 .vendor = PCI_VENDOR_ID_ATI,
207 .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
208};
209
Frank Vibrans63e62b02011-02-14 18:38:14 +0000210static struct device_operations azalia_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200211 .read_resources = pci_dev_read_resources,
212 .set_resources = pci_dev_set_resources,
213 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200214 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000215};
216
217static const struct pci_driver azalia_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200218 .ops = &azalia_ops,
219 .vendor = PCI_VENDOR_ID_ATI,
220 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000221};
222
Frank Vibrans63e62b02011-02-14 18:38:14 +0000223static struct device_operations gec_ops = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200224 .read_resources = pci_dev_read_resources,
225 .set_resources = pci_dev_set_resources,
226 .enable_resources = pci_dev_enable_resources,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200227 .ops_pci = &pci_dev_ops_pci,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000228};
229
230static const struct pci_driver gec_driver __pci_driver = {
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200231 .ops = &gec_ops,
232 .vendor = PCI_VENDOR_ID_ATI,
233 .device = PCI_DEVICE_ID_ATI_SB800_GEC,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000234};
235
Kerry She3e706b62011-06-24 22:52:15 +0800236/**
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200237 * Fill build time defaults.
238 */
239static void sb800_init(void *chip_info)
240{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200241 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200242 sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry;
243 sb800_cimx_config(sb_config);
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200244
Paul Menzel114a9482015-10-25 22:27:42 +0100245 /* Initially enable all GPP ports 0 to 3 */
Kyösti Mälkki24501ca2015-02-07 17:38:45 +0200246 abcfg_reg(0xc0, 0x01FF, 0x0F4);
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200247}
248
249/**
Kerry Shefeed3292011-08-18 18:03:44 +0800250 * South Bridge CIMx ramstage entry point wrapper.
251 */
252void sb_Before_Pci_Init(void)
253{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200254 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800255 sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
256 AmdSbDispatcher(sb_config);
257}
258
259void sb_After_Pci_Init(void)
260{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200261 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800262 sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
263 AmdSbDispatcher(sb_config);
264}
265
266void sb_Mid_Post_Init(void)
267{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200268 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800269 sb_config->StdHeader.Func = SB_MID_POST_INIT;
270 AmdSbDispatcher(sb_config);
271}
272
273void sb_Late_Post(void)
274{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200275 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
Kerry Shefeed3292011-08-18 18:03:44 +0800276 sb_config->StdHeader.Func = SB_LATE_POST_INIT;
277 AmdSbDispatcher(sb_config);
278}
279
zbao9bcdbf82012-04-05 13:18:49 +0800280void sb_Before_Pci_Restore_Init(void)
281{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200282 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800283 sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT;
284 AmdSbDispatcher(sb_config);
285}
286
287void sb_After_Pci_Restore_Init(void)
288{
Kyösti Mälkki1498efe2017-03-09 16:25:24 +0200289 printk(BIOS_DEBUG, "SB800: %s\n", __func__);
zbao9bcdbf82012-04-05 13:18:49 +0800290 sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT;
291 AmdSbDispatcher(sb_config);
292}
Kerry Shefeed3292011-08-18 18:03:44 +0800293
Mike Loptienc93a75a2014-06-06 15:16:29 -0600294/*
295 * Update the PCI devices with a valid IRQ number
296 * that is set in the mainboard PCI_IRQ structures.
297 */
298static void set_pci_irqs(void *unused)
299{
300 /* Write PCI_INTR regs 0xC00/0xC01 */
301 write_pci_int_table();
302
303 /* Write IRQs for all devicetree enabled devices */
304 write_pci_cfg_irqs();
305}
306
307/*
308 * Hook this function into the PCI state machine
309 * on entry into BS_DEV_ENABLE.
310 */
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500311BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);
Mike Loptienc93a75a2014-06-06 15:16:29 -0600312
Kerry Shefeed3292011-08-18 18:03:44 +0800313/**
Frank Vibrans63e62b02011-02-14 18:38:14 +0000314 * @brief SB Cimx entry point sbBeforePciInit wrapper
315 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200316static void sb800_enable(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000317{
efdesign9805a89ab2011-06-20 17:38:49 -0700318 struct southbridge_amd_cimx_sb800_config *sb_chip =
319 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000320
Frank Vibrans63e62b02011-02-14 18:38:14 +0000321 switch (dev->path.pci.devfn) {
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300322 case PCI_DEVFN(0x11, 0): /* 0:11.0 SATA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000323 if (dev->enabled) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200324 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100325 if (sb_chip->boot_switch_sata_ide == 1)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000326 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100327 else if (sb_chip->boot_switch_sata_ide == 0)
Frank Vibrans63e62b02011-02-14 18:38:14 +0000328 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
329 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200330 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000331 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000332 break;
333
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300334 case PCI_DEVFN(0x14, 0): /* 0:14:0 SMBUS */
Kyösti Mälkki35546de2014-04-17 15:07:32 +0300335 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800336 setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000337 break;
338
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300339 case PCI_DEVFN(0x14, 1): /* 0:14:1 IDE */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000340 break;
341
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300342 case PCI_DEVFN(0x14, 2): /* 0:14:2 HDA */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000343 if (dev->enabled) {
Elyes HAOUAS0f8b8d92019-01-03 10:23:28 +0100344 if (sb_config->AzaliaController == AZALIA_DISABLE) {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200345 sb_config->AzaliaController = AZALIA_AUTO;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000346 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000347 } else {
Elyes HAOUASb0f19882018-06-09 11:59:00 +0200348 sb_config->AzaliaController = AZALIA_DISABLE;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000349 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000350 break;
351
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300352 case PCI_DEVFN(0x14, 3): /* 0:14:3 LPC */
Martin Rothe899e512012-12-05 16:07:11 -0700353 /* Initialize the fans */
Julius Wernercd49cce2019-03-05 16:53:33 -0800354#if CONFIG(SB800_IMC_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700355 init_sb800_IMC_fans(dev);
Julius Wernercd49cce2019-03-05 16:53:33 -0800356#elif CONFIG(SB800_MANUAL_FAN_CONTROL)
Martin Rothe899e512012-12-05 16:07:11 -0700357 init_sb800_MANUAL_fans(dev);
358#endif
Frank Vibrans63e62b02011-02-14 18:38:14 +0000359 break;
360
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300361 case PCI_DEVFN(0x14, 4): /* 0:14:4 PCI */
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200362 /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
363 * 'PCIDisable' set to 0 to enable P2P bridge.
364 * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
365 * to function as GPIO {GPIO 35:0}.
366 */
Kyösti Mälkki0b87bb72014-11-11 17:22:23 +0200367 if (!sb_chip->disconnect_pcib && dev->enabled)
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100368 pm_write8(0xea, pm_read8(0xea) & 0xfe);
Kyösti Mälkki486c05f2015-01-17 18:08:40 +0200369 else
Michał Żygowski287ce5f2019-12-01 17:41:23 +0100370 pm_write8(0xea, (pm_read8(0xea) & 0xfe) | 1);
Frank Vibrans63e62b02011-02-14 18:38:14 +0000371 break;
372
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300373 case PCI_DEVFN(0x14, 6): /* 0:14:6 GEC */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000374 if (dev->enabled) {
375 sb_config->GecConfig = 0;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000376 } else {
377 sb_config->GecConfig = 1;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000378 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000379 break;
380
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300381 case PCI_DEVFN(0x15, 0): /* 0:15:0 PCIe PortA */
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500382 {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +0200383 struct device *device;
Paul Menzele4a016f2013-03-01 13:05:04 +0100384 for (device = dev; device; device = device->sibling) {
385 if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break;
Kerry Shefeed3292011-08-18 18:03:44 +0800386 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
387 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000388
Kerry Shefeed3292011-08-18 18:03:44 +0800389 /*
390 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
391 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
392 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
393 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
394 */
395 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
Scott Duplichan8fed77a2011-06-18 10:46:45 -0500396 }
Kerry Shefeed3292011-08-18 18:03:44 +0800397 break;
398
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300399 case PCI_DEVFN(0x12, 0): /* 0:12:0 OHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800400 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
401 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300402 case PCI_DEVFN(0x12, 2): /* 0:12:2 EHCI-USB1 */
Kerry Shefeed3292011-08-18 18:03:44 +0800403 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
404 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300405 case PCI_DEVFN(0x13, 0): /* 0:13:0 OHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800406 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
407 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300408 case PCI_DEVFN(0x13, 2): /* 0:13:2 EHCI-USB2 */
Kerry Shefeed3292011-08-18 18:03:44 +0800409 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
410 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300411 case PCI_DEVFN(0x14, 5): /* 0:14:5 OHCI-USB4 */
Kerry Shefeed3292011-08-18 18:03:44 +0800412 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
413 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300414 case PCI_DEVFN(0x16, 0): /* 0:16:0 OHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800415 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
416 break;
Kyösti Mälkkidda0fc42018-05-20 14:17:19 +0300417 case PCI_DEVFN(0x16, 2): /* 0:16:2 EHCI-USB3 */
Kerry Shefeed3292011-08-18 18:03:44 +0800418 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
419
Kyösti Mälkki9de8ab92017-09-09 16:51:34 +0300420 /* FIXME: Find better callsites for these.
421 * call the CIMX entry at the last sb800 device,
Kerry Sheh75df1062011-10-10 19:19:46 +0800422 * so make sure the mainboard devicetree is complete
423 */
Kyösti Mälkkic551caa2014-06-20 12:31:23 +0300424 if (!acpi_is_wakeup_s3())
zbao9bcdbf82012-04-05 13:18:49 +0800425 sb_Before_Pci_Init();
426 else
427 sb_Before_Pci_Restore_Init();
Kerry Shefeed3292011-08-18 18:03:44 +0800428 break;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000429
430 default:
431 break;
432 }
Frank Vibrans63e62b02011-02-14 18:38:14 +0000433}
434
efdesign9805a89ab2011-06-20 17:38:49 -0700435struct chip_operations southbridge_amd_cimx_sb800_ops = {
Frank Vibrans63e62b02011-02-14 18:38:14 +0000436 CHIP_NAME("ATI SB800")
Kyösti Mälkki41cd0472015-02-07 11:20:54 +0200437 .init = sb800_init,
Frank Vibrans63e62b02011-02-14 18:38:14 +0000438 .enable_dev = sb800_enable,
439};