blob: 59e293f70fff1db338dbcd13707a975c6073e766 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03002
Michał Żygowskif3db2ae2019-11-24 13:26:10 +01003#include <amdblocks/acpimmio.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03004#include <console/console.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03005#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02006#include <device/mmio.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07007#include <acpi/acpi.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03008#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
11#include <device/pci_ops.h>
Elyes HAOUASab89edb2019-05-15 21:10:44 +020012#include <types.h>
13
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030014#include "hudson.h"
15#include "smbus.h"
16#include "smi.h"
WANG Siyuanc7667f02015-06-23 22:28:17 +080017#include "fchec.h"
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030018
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030019int acpi_get_sleep_type(void)
20{
21 u16 tmp = inw(ACPI_PM1_CNT_BLK);
22 tmp = ((tmp & (7 << 10)) >> 10);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030023 return (int)tmp;
24}
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030025
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020026void hudson_enable(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030027{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +010028 printk(BIOS_DEBUG, "%s()\n", __func__);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030029 switch (dev->path.pci.devfn) {
Kyösti Mälkkib11d4e32018-05-20 10:39:10 +030030 case PCI_DEVFN(0x14, 7): /* SD */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030031 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030032 u32 sd_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030033 /* turn off the SDHC controller in the PM reg */
34 u8 reg8;
Felix Singer43b7f412022-03-07 04:34:52 +010035 if (sd_device_id == PCI_DID_AMD_HUDSON_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060036 reg8 = pm_read8(PM_HUD_SD_FLASH_CTRL);
37 reg8 &= ~BIT(0);
38 pm_write8(PM_HUD_SD_FLASH_CTRL, reg8);
Felix Singer43b7f412022-03-07 04:34:52 +010039 } else if (sd_device_id == PCI_DID_AMD_YANGTZE_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060040 reg8 = pm_read8(PM_YANG_SD_FLASH_CTRL);
41 reg8 &= ~BIT(0);
42 pm_write8(PM_YANG_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030043 }
44 /* remove device 0:14.7 from PCI space */
Marc Jonesd7717862017-04-09 17:55:56 -060045 reg8 = pm_read8(PM_MANUAL_RESET);
46 reg8 &= ~BIT(6);
47 pm_write8(PM_MANUAL_RESET, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030048 }
49 break;
50 default:
51 break;
52 }
53}
54
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030055static void hudson_init_acpi_ports(void)
56{
57 /* We use some of these ports in SMM regardless of whether or not
58 * ACPI tables are generated. Enable these ports indiscriminately.
59 */
60
Marc Jonesd7717862017-04-09 17:55:56 -060061 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
62 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
63 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
64 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -060065 /* CpuControl is in \_PR.CP00, 6 bytes */
Marc Jonesd7717862017-04-09 17:55:56 -060066 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030067
Julius Wernercd49cce2019-03-05 16:53:33 -080068 if (CONFIG(HAVE_SMI_HANDLER)) {
Marc Jonesd7717862017-04-09 17:55:56 -060069 pm_write16(PM_ACPI_SMI_CMD, ACPI_SMI_CTL_PORT);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030070 hudson_enable_acpi_cmd_smi();
71 } else {
Marc Jonesd7717862017-04-09 17:55:56 -060072 pm_write16(PM_ACPI_SMI_CMD, 0);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030073 }
74
75 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
76 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
77 */
Marc Jonesd7717862017-04-09 17:55:56 -060078 pm_write8(PM_ACPI_CONF, BIT(0) | BIT(1) | BIT(4) | BIT(2));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030079}
80
81static void hudson_init(void *chip_info)
82{
83 hudson_init_acpi_ports();
84}
85
86static void hudson_final(void *chip_info)
87{
Julius Wernercd49cce2019-03-05 16:53:33 -080088 if (CONFIG(HUDSON_IMC_FWM)) {
Kyösti Mälkkieb064b32017-08-24 21:20:10 +030089 agesawrapper_fchecfancontrolservice();
Arthur Heymans03a6ccd2022-11-01 23:38:19 +010090 enable_imc_thermal_zone();
Kyösti Mälkkieb064b32017-08-24 21:20:10 +030091 }
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030092}
93
Dave Frodinbc21a412015-01-19 11:40:38 -070094struct chip_operations southbridge_amd_pi_hudson_ops = {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030095 CHIP_NAME("ATI HUDSON")
96 .enable_dev = hudson_enable,
97 .init = hudson_init,
98 .final = hudson_final
99};