blob: f95b2fb488f3ff3e47b0f64c5aec2ca965f879d3 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
zbao246e84b2012-07-13 18:47:03 +08002
Michał Żygowskif3db2ae2019-11-24 13:26:10 +01003#include <amdblocks/acpimmio.h>
zbao246e84b2012-07-13 18:47:03 +08004#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
zbao246e84b2012-07-13 18:47:03 +08006#include <device/device.h>
7#include <device/pci.h>
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +03008#include <device/pci_def.h>
zbao246e84b2012-07-13 18:47:03 +08009#include <device/pci_ids.h>
10#include <device/pci_ops.h>
zbao246e84b2012-07-13 18:47:03 +080011#include "hudson.h"
Kyösti Mälkki29d9c562014-10-16 21:35:48 +030012#include "imc.h"
zbao246e84b2012-07-13 18:47:03 +080013#include "smbus.h"
Alexandru Gagniuc86777e32014-04-20 14:36:29 -050014#include "smi.h"
zbao246e84b2012-07-13 18:47:03 +080015
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050016#define PM_REG_USB_ENABLE 0xef
17
18enum usb_enable {
19 USB_EN_DEVFN_12_0 = (1 << 0),
20 USB_EN_DEVFN_12_2 = (1 << 1),
21 USB_EN_DEVFN_13_0 = (1 << 2),
22 USB_EN_DEVFN_13_2 = (1 << 3),
23 USB_EN_DEVFN_16_0 = (1 << 4),
24 USB_EN_DEVFN_16_2 = (1 << 5),
25};
26
27static void hudson_disable_usb(u8 disable)
28{
29 u8 reg8;
30
31 /* Bit 7 handles routing, 6 is reserved. we don't mess with those */
32 disable &= 0x3f;
33
34 reg8 = pm_read8(PM_REG_USB_ENABLE);
35 reg8 &= ~disable;
36 pm_write8(PM_REG_USB_ENABLE, reg8);
37}
38
Elyes HAOUASa93e7542018-05-19 14:30:47 +020039void hudson_enable(struct device *dev)
zbao246e84b2012-07-13 18:47:03 +080040{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +010041 printk(BIOS_DEBUG, "%s()\n", __func__);
Dave Frodinea909632013-05-31 08:15:57 -060042 switch (dev->path.pci.devfn) {
Tobias Diedrichae3adff2014-11-08 00:38:33 +010043 case PCI_DEVFN(0x14, 5):
44 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030045 u32 usb_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Tobias Diedrichae3adff2014-11-08 00:38:33 +010046 u8 reg8;
Felix Singer43b7f412022-03-07 04:34:52 +010047 if (usb_device_id == PCI_DID_AMD_SB900_USB_20_5) {
Tobias Diedrichae3adff2014-11-08 00:38:33 +010048 /* turn off and remove device 0:14.5 from PCI space */
49 reg8 = pm_read8(0xef);
50 reg8 &= ~(1 << 6);
51 pm_write8(0xef, reg8);
52 }
53 }
54 break;
55
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050056 case PCI_DEVFN(0x14, 7):
Dave Frodinea909632013-05-31 08:15:57 -060057 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030058 u32 sd_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Dave Frodinea909632013-05-31 08:15:57 -060059 /* turn off the SDHC controller in the PM reg */
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050060 u8 reg8;
Felix Singer43b7f412022-03-07 04:34:52 +010061 if (sd_device_id == PCI_DID_AMD_HUDSON_SD) {
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050062 reg8 = pm_read8(0xe7);
63 reg8 &= ~(1 << 0);
64 pm_write8(0xe7, reg8);
Felix Singer43b7f412022-03-07 04:34:52 +010065 } else if (sd_device_id == PCI_DID_AMD_YANGTZE_SD) {
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050066 reg8 = pm_read8(0xe8);
67 reg8 &= ~(1 << 0);
68 pm_write8(0xe8, reg8);
Dave Frodinea909632013-05-31 08:15:57 -060069 }
70 /* remove device 0:14.7 from PCI space */
Alexandru Gagniuc342ac642014-04-14 16:44:19 -050071 reg8 = pm_read8(0xd3);
72 reg8 &= ~(1 << 6);
73 pm_write8(0xd3, reg8);
Dave Frodinea909632013-05-31 08:15:57 -060074 }
75 break;
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050076
77 /* Make sure to disable other functions if function 0 is disabled */
78 case PCI_DEVFN(0x12, 0):
79 if (dev->enabled == 0)
80 hudson_disable_usb(USB_EN_DEVFN_12_0);
Arthur Heymansfff20212021-03-15 14:56:16 +010081 __fallthrough;
Jacob Garber4c33a3a2019-07-12 10:34:06 -060082 case PCI_DEVFN(0x12, 2):
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050083 if (dev->enabled == 0)
84 hudson_disable_usb(USB_EN_DEVFN_12_2);
85 break;
86 case PCI_DEVFN(0x13, 0):
87 if (dev->enabled == 0)
88 hudson_disable_usb(USB_EN_DEVFN_13_0);
Arthur Heymansfff20212021-03-15 14:56:16 +010089 __fallthrough;
Jacob Garber4c33a3a2019-07-12 10:34:06 -060090 case PCI_DEVFN(0x13, 2):
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050091 if (dev->enabled == 0)
92 hudson_disable_usb(USB_EN_DEVFN_13_2);
93 break;
94 case PCI_DEVFN(0x16, 0):
95 if (dev->enabled == 0)
96 hudson_disable_usb(USB_EN_DEVFN_16_0);
Arthur Heymansfff20212021-03-15 14:56:16 +010097 __fallthrough;
Jacob Garber4c33a3a2019-07-12 10:34:06 -060098 case PCI_DEVFN(0x16, 2):
Alexandru Gagniucd2e5f682014-04-16 16:33:03 -050099 if (dev->enabled == 0)
100 hudson_disable_usb(USB_EN_DEVFN_16_2);
101 break;
Dave Frodinea909632013-05-31 08:15:57 -0600102 default:
103 break;
104 }
zbao246e84b2012-07-13 18:47:03 +0800105}
106
Alexandru Gagniuc86777e32014-04-20 14:36:29 -0500107static void hudson_init_acpi_ports(void)
108{
109 /* We use some of these ports in SMM regardless of whether or not
110 * ACPI tables are generated. Enable these ports indiscriminately.
111 */
112
113 pm_write16(0x60, ACPI_PM_EVT_BLK);
114 pm_write16(0x62, ACPI_PM1_CNT_BLK);
115 pm_write16(0x64, ACPI_PM_TMR_BLK);
116 pm_write16(0x68, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -0600117 /* CpuControl is in \_PR.CP00, 6 bytes */
Alexandru Gagniuc86777e32014-04-20 14:36:29 -0500118 pm_write16(0x66, ACPI_CPU_CONTROL);
119
Julius Wernercd49cce2019-03-05 16:53:33 -0800120 if (CONFIG(HAVE_SMI_HANDLER)) {
Alexandru Gagniuc86777e32014-04-20 14:36:29 -0500121 pm_write16(0x6a, ACPI_SMI_CTL_PORT);
122 hudson_enable_acpi_cmd_smi();
123 } else {
124 pm_write16(0x6a, 0);
125 }
126
127 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
128 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
129 */
130 pm_write8(0x74, 1<<0 | 1<<1 | 1<<4 | 1<<2);
131}
132
133static void hudson_init(void *chip_info)
134{
135 hudson_init_acpi_ports();
136}
137
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300138static void hudson_final(void *chip_info)
139{
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300140 /* AMD AGESA does not enable thermal zone, so we enable it here. */
Julius Wernercd49cce2019-03-05 16:53:33 -0800141 if (CONFIG(HUDSON_IMC_FWM) &&
142 !CONFIG(ACPI_ENABLE_THERMAL_ZONE))
Kyösti Mälkkieb064b32017-08-24 21:20:10 +0300143 enable_imc_thermal_zone();
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300144}
145
zbao246e84b2012-07-13 18:47:03 +0800146struct chip_operations southbridge_amd_agesa_hudson_ops = {
147 CHIP_NAME("ATI HUDSON")
148 .enable_dev = hudson_enable,
Kyösti Mälkki29d9c562014-10-16 21:35:48 +0300149 .init = hudson_init,
150 .final = hudson_final
zbao246e84b2012-07-13 18:47:03 +0800151};