blob: a331c572620f1c9aee22bdce4c05ffbe0cb89504 [file] [log] [blame]
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030014 */
15
16#include <console/console.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030017#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030019#include <arch/acpi.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030020#include <device/device.h>
21#include <device/pci.h>
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030022#include <device/pci_def.h>
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030023#include <device/pci_ids.h>
24#include <device/pci_ops.h>
Elyes HAOUASab89edb2019-05-15 21:10:44 +020025#include <types.h>
26
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030027#include "hudson.h"
28#include "smbus.h"
29#include "smi.h"
WANG Siyuanc7667f02015-06-23 22:28:17 +080030#include "fchec.h"
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030031
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030032int acpi_get_sleep_type(void)
33{
34 u16 tmp = inw(ACPI_PM1_CNT_BLK);
35 tmp = ((tmp & (7 << 10)) >> 10);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030036 return (int)tmp;
37}
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030038
39void pm_write8(u8 reg, u8 value)
40{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080041 write8((void *)(PM_MMIO_BASE + reg), value);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030042}
43
44u8 pm_read8(u8 reg)
45{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080046 return read8((void *)(PM_MMIO_BASE + reg));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030047}
48
49void pm_write16(u8 reg, u16 value)
50{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080051 write16((void *)(PM_MMIO_BASE + reg), value);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030052}
53
54u16 pm_read16(u16 reg)
55{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080056 return read16((void *)(PM_MMIO_BASE + reg));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030057}
58
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020059void hudson_enable(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030060{
61 printk(BIOS_DEBUG, "hudson_enable()\n");
62 switch (dev->path.pci.devfn) {
Kyösti Mälkkib11d4e32018-05-20 10:39:10 +030063 case PCI_DEVFN(0x14, 7): /* SD */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030064 if (dev->enabled == 0) {
Kyösti Mälkki0bc06ab2018-05-20 15:41:05 +030065 u32 sd_device_id = pci_read_config16(dev, PCI_DEVICE_ID);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030066 /* turn off the SDHC controller in the PM reg */
67 u8 reg8;
68 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060069 reg8 = pm_read8(PM_HUD_SD_FLASH_CTRL);
70 reg8 &= ~BIT(0);
71 pm_write8(PM_HUD_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030072 }
73 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060074 reg8 = pm_read8(PM_YANG_SD_FLASH_CTRL);
75 reg8 &= ~BIT(0);
76 pm_write8(PM_YANG_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030077 }
78 /* remove device 0:14.7 from PCI space */
Marc Jonesd7717862017-04-09 17:55:56 -060079 reg8 = pm_read8(PM_MANUAL_RESET);
80 reg8 &= ~BIT(6);
81 pm_write8(PM_MANUAL_RESET, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030082 }
83 break;
84 default:
85 break;
86 }
87}
88
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030089static void hudson_init_acpi_ports(void)
90{
91 /* We use some of these ports in SMM regardless of whether or not
92 * ACPI tables are generated. Enable these ports indiscriminately.
93 */
94
Marc Jonesd7717862017-04-09 17:55:56 -060095 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
96 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
97 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
98 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -060099 /* CpuControl is in \_PR.CP00, 6 bytes */
Marc Jonesd7717862017-04-09 17:55:56 -0600100 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300101
Julius Wernercd49cce2019-03-05 16:53:33 -0800102 if (CONFIG(HAVE_SMI_HANDLER)) {
Marc Jonesd7717862017-04-09 17:55:56 -0600103 pm_write16(PM_ACPI_SMI_CMD, ACPI_SMI_CTL_PORT);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300104 hudson_enable_acpi_cmd_smi();
105 } else {
Marc Jonesd7717862017-04-09 17:55:56 -0600106 pm_write16(PM_ACPI_SMI_CMD, 0);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300107 }
108
109 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
110 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
111 */
Marc Jonesd7717862017-04-09 17:55:56 -0600112 pm_write8(PM_ACPI_CONF, BIT(0) | BIT(1) | BIT(4) | BIT(2));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300113}
114
115static void hudson_init(void *chip_info)
116{
117 hudson_init_acpi_ports();
118}
119
120static void hudson_final(void *chip_info)
121{
Julius Wernercd49cce2019-03-05 16:53:33 -0800122 if (CONFIG(HUDSON_IMC_FWM)) {
Kyösti Mälkkieb064b32017-08-24 21:20:10 +0300123 agesawrapper_fchecfancontrolservice();
Julius Wernercd49cce2019-03-05 16:53:33 -0800124 if (!CONFIG(ACPI_ENABLE_THERMAL_ZONE))
Kyösti Mälkkieb064b32017-08-24 21:20:10 +0300125 enable_imc_thermal_zone();
126 }
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300127}
128
Dave Frodinbc21a412015-01-19 11:40:38 -0700129struct chip_operations southbridge_amd_pi_hudson_ops = {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300130 CHIP_NAME("ATI HUDSON")
131 .enable_dev = hudson_enable,
132 .init = hudson_init,
133 .final = hudson_final
134};