blob: 852144b2dbfff169cf0d902b7feff01ad52998de [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>
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030010#include <device/pci_def.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030011#include <device/pci_ids.h>
12#include <device/pci_ops.h>
Elyes HAOUASab89edb2019-05-15 21:10:44 +020013#include <types.h>
14
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030015#include "hudson.h"
16#include "smbus.h"
17#include "smi.h"
WANG Siyuanc7667f02015-06-23 22:28:17 +080018#include "fchec.h"
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030019
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030020int acpi_get_sleep_type(void)
21{
22 u16 tmp = inw(ACPI_PM1_CNT_BLK);
23 tmp = ((tmp & (7 << 10)) >> 10);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030024 return (int)tmp;
25}
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030026
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020027void hudson_enable(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030028{
Elyes HAOUASbfc255a2020-03-07 13:05:14 +010029 printk(BIOS_DEBUG, "%s()\n", __func__);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030030 switch (dev->path.pci.devfn) {
Kyösti Mälkkib11d4e32018-05-20 10:39:10 +030031 case PCI_DEVFN(0x14, 7): /* SD */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030032 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030033 u32 sd_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030034 /* turn off the SDHC controller in the PM reg */
35 u8 reg8;
36 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060037 reg8 = pm_read8(PM_HUD_SD_FLASH_CTRL);
38 reg8 &= ~BIT(0);
39 pm_write8(PM_HUD_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030040 }
41 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060042 reg8 = pm_read8(PM_YANG_SD_FLASH_CTRL);
43 reg8 &= ~BIT(0);
44 pm_write8(PM_YANG_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030045 }
46 /* remove device 0:14.7 from PCI space */
Marc Jonesd7717862017-04-09 17:55:56 -060047 reg8 = pm_read8(PM_MANUAL_RESET);
48 reg8 &= ~BIT(6);
49 pm_write8(PM_MANUAL_RESET, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030050 }
51 break;
52 default:
53 break;
54 }
55}
56
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030057static void hudson_init_acpi_ports(void)
58{
59 /* We use some of these ports in SMM regardless of whether or not
60 * ACPI tables are generated. Enable these ports indiscriminately.
61 */
62
Marc Jonesd7717862017-04-09 17:55:56 -060063 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
64 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
65 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
66 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -060067 /* CpuControl is in \_PR.CP00, 6 bytes */
Marc Jonesd7717862017-04-09 17:55:56 -060068 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030069
Julius Wernercd49cce2019-03-05 16:53:33 -080070 if (CONFIG(HAVE_SMI_HANDLER)) {
Marc Jonesd7717862017-04-09 17:55:56 -060071 pm_write16(PM_ACPI_SMI_CMD, ACPI_SMI_CTL_PORT);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030072 hudson_enable_acpi_cmd_smi();
73 } else {
Marc Jonesd7717862017-04-09 17:55:56 -060074 pm_write16(PM_ACPI_SMI_CMD, 0);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030075 }
76
77 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
78 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
79 */
Marc Jonesd7717862017-04-09 17:55:56 -060080 pm_write8(PM_ACPI_CONF, BIT(0) | BIT(1) | BIT(4) | BIT(2));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030081}
82
83static void hudson_init(void *chip_info)
84{
85 hudson_init_acpi_ports();
86}
87
88static void hudson_final(void *chip_info)
89{
Julius Wernercd49cce2019-03-05 16:53:33 -080090 if (CONFIG(HUDSON_IMC_FWM)) {
Kyösti Mälkkieb064b32017-08-24 21:20:10 +030091 agesawrapper_fchecfancontrolservice();
Julius Wernercd49cce2019-03-05 16:53:33 -080092 if (!CONFIG(ACPI_ENABLE_THERMAL_ZONE))
Kyösti Mälkkieb064b32017-08-24 21:20:10 +030093 enable_imc_thermal_zone();
94 }
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030095}
96
Dave Frodinbc21a412015-01-19 11:40:38 -070097struct chip_operations southbridge_amd_pi_hudson_ops = {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030098 CHIP_NAME("ATI HUDSON")
99 .enable_dev = hudson_enable,
100 .init = hudson_init,
101 .final = hudson_final
102};