blob: ca6b46b58ac8d174dad67d7be6e669e7757593dd [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. */
zbao246e84b2012-07-13 18:47:03 +08003
Michał Żygowskif3db2ae2019-11-24 13:26:10 +01004#include <amdblocks/acpimmio.h>
zbao246e84b2012-07-13 18:47:03 +08005#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02006#include <device/mmio.h>
zbao246e84b2012-07-13 18:47:03 +08007#include <device/device.h>
8#include <device/pci.h>
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +03009#include <device/pci_def.h>
zbao246e84b2012-07-13 18:47:03 +080010#include <device/pci_ids.h>
11#include <device/pci_ops.h>
zbao246e84b2012-07-13 18:47:03 +080012#include "hudson.h"
Kyösti Mälkki29d9c562014-10-16 21:35:48 +030013#include "imc.h"
zbao246e84b2012-07-13 18:47:03 +080014#include "smbus.h"
Alexandru Gagniuc86777e32014-04-20 14:36:29 -050015#include "smi.h"
zbao246e84b2012-07-13 18:47:03 +080016
zbao246e84b2012-07-13 18:47:03 +080017
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050018#define PM_REG_USB_ENABLE 0xef
19
20enum usb_enable {
21 USB_EN_DEVFN_12_0 = (1 << 0),
22 USB_EN_DEVFN_12_2 = (1 << 1),
23 USB_EN_DEVFN_13_0 = (1 << 2),
24 USB_EN_DEVFN_13_2 = (1 << 3),
25 USB_EN_DEVFN_16_0 = (1 << 4),
26 USB_EN_DEVFN_16_2 = (1 << 5),
27};
28
29static void hudson_disable_usb(u8 disable)
30{
31 u8 reg8;
32
33 /* Bit 7 handles routing, 6 is reserved. we don't mess with those */
34 disable &= 0x3f;
35
36 reg8 = pm_read8(PM_REG_USB_ENABLE);
37 reg8 &= ~disable;
38 pm_write8(PM_REG_USB_ENABLE, reg8);
39}
40
Elyes HAOUASa93e7542018-05-19 14:30:47 +020041void hudson_enable(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +080042{
Martin Rothf5726ea2013-01-18 12:55:40 -070043 printk(BIOS_DEBUG, "hudson_enable()\n");
Dave Frodinea909632013-05-31 08:15:57 -060044 switch (dev->path.pci.devfn) {
Tobias Diedrichae3adff2014-11-08 00:38:33 +010045 case PCI_DEVFN(0x14, 5):
46 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030047 u32 usb_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Tobias Diedrichae3adff2014-11-08 00:38:33 +010048 u8 reg8;
Kyösti Mälkki9d9a5522016-11-19 22:14:59 +020049 if (usb_device_id == PCI_DEVICE_ID_AMD_SB900_USB_20_5) {
Tobias Diedrichae3adff2014-11-08 00:38:33 +010050 /* turn off and remove device 0:14.5 from PCI space */
51 reg8 = pm_read8(0xef);
52 reg8 &= ~(1 << 6);
53 pm_write8(0xef, reg8);
54 }
55 }
56 break;
57
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050058 case PCI_DEVFN(0x14, 7):
Dave Frodinea909632013-05-31 08:15:57 -060059 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030060 u32 sd_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Dave Frodinea909632013-05-31 08:15:57 -060061 /* turn off the SDHC controller in the PM reg */
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050062 u8 reg8;
Dave Frodinea909632013-05-31 08:15:57 -060063 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050064 reg8 = pm_read8(0xe7);
65 reg8 &= ~(1 << 0);
66 pm_write8(0xe7, reg8);
Dave Frodinea909632013-05-31 08:15:57 -060067 }
68 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050069 reg8 = pm_read8(0xe8);
70 reg8 &= ~(1 << 0);
71 pm_write8(0xe8, reg8);
Dave Frodinea909632013-05-31 08:15:57 -060072 }
73 /* remove device 0:14.7 from PCI space */
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050074 reg8 = pm_read8(0xd3);
75 reg8 &= ~(1 << 6);
76 pm_write8(0xd3, reg8);
Dave Frodinea909632013-05-31 08:15:57 -060077 }
78 break;
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050079
80 /* Make sure to disable other functions if function 0 is disabled */
81 case PCI_DEVFN(0x12, 0):
82 if (dev->enabled == 0)
83 hudson_disable_usb(USB_EN_DEVFN_12_0);
Jacob Garber4c33a3a2019-07-12 10:34:06 -060084 /* fall through */
85 case PCI_DEVFN(0x12, 2):
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050086 if (dev->enabled == 0)
87 hudson_disable_usb(USB_EN_DEVFN_12_2);
88 break;
89 case PCI_DEVFN(0x13, 0):
90 if (dev->enabled == 0)
91 hudson_disable_usb(USB_EN_DEVFN_13_0);
Jacob Garber4c33a3a2019-07-12 10:34:06 -060092 /* fall through */
93 case PCI_DEVFN(0x13, 2):
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050094 if (dev->enabled == 0)
95 hudson_disable_usb(USB_EN_DEVFN_13_2);
96 break;
97 case PCI_DEVFN(0x16, 0):
98 if (dev->enabled == 0)
99 hudson_disable_usb(USB_EN_DEVFN_16_0);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600100 /* fall through */
101 case PCI_DEVFN(0x16, 2):
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -0500102 if (dev->enabled == 0)
103 hudson_disable_usb(USB_EN_DEVFN_16_2);
104 break;
Dave Frodinea909632013-05-31 08:15:57 -0600105 default:
106 break;
107 }
zbao246e84b2012-07-13 18:47:03 +0800108}
109
zbao246e84b2012-07-13 18:47:03 +0800110
Alexandru Gagniuc86777e32014-04-20 14:36:29 -0500111static void hudson_init_acpi_ports(void)
112{
113 /* We use some of these ports in SMM regardless of whether or not
114 * ACPI tables are generated. Enable these ports indiscriminately.
115 */
116
117 pm_write16(0x60, ACPI_PM_EVT_BLK);
118 pm_write16(0x62, ACPI_PM1_CNT_BLK);
119 pm_write16(0x64, ACPI_PM_TMR_BLK);
120 pm_write16(0x68, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -0600121 /* CpuControl is in \_PR.CP00, 6 bytes */
Alexandru Gagniuc86777e32014-04-20 14:36:29 -0500122 pm_write16(0x66, ACPI_CPU_CONTROL);
123
Julius Wernercd49cce2019-03-05 16:53:33 -0800124 if (CONFIG(HAVE_SMI_HANDLER)) {
Alexandru Gagniuc86777e32014-04-20 14:36:29 -0500125 pm_write16(0x6a, ACPI_SMI_CTL_PORT);
126 hudson_enable_acpi_cmd_smi();
127 } else {
128 pm_write16(0x6a, 0);
129 }
130
131 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
132 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
133 */
134 pm_write8(0x74, 1<<0 | 1<<1 | 1<<4 | 1<<2);
135}
136
137static void hudson_init(void *chip_info)
138{
139 hudson_init_acpi_ports();
140}
141
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300142static void hudson_final(void *chip_info)
143{
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300144 /* AMD AGESA does not enable thermal zone, so we enable it here. */
Julius Wernercd49cce2019-03-05 16:53:33 -0800145 if (CONFIG(HUDSON_IMC_FWM) &&
146 !CONFIG(ACPI_ENABLE_THERMAL_ZONE))
Kyösti Mälkkieb064b32017-08-24 21:20:10 +0300147 enable_imc_thermal_zone();
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300148}
149
zbao246e84b2012-07-13 18:47:03 +0800150struct chip_operations southbridge_amd_agesa_hudson_ops = {
151 CHIP_NAME("ATI HUDSON")
152 .enable_dev = hudson_enable,
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300153 .init = hudson_init,
154 .final = hudson_final
zbao246e84b2012-07-13 18:47:03 +0800155};