blob: 073e41e645dfe4f422d7e8a3c3e9be6973cd51c8 [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>
17
18#include <arch/io.h>
19#include <arch/acpi.h>
20
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <device/pci_ops.h>
25#include <cbmem.h>
26#include "hudson.h"
27#include "smbus.h"
28#include "smi.h"
WANG Siyuanc7667f02015-06-23 22:28:17 +080029#if IS_ENABLED(CONFIG_HUDSON_IMC_FWM)
30#include "fchec.h"
31#endif
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030032
33/* Offsets from ACPI_MMIO_BASE
34 * This is defined by AGESA, but we don't include AGESA headers to avoid
Dave Frodinbc21a412015-01-19 11:40:38 -070035 * polluting the namespace.
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030036 */
37#define PM_MMIO_BASE 0xfed80300
38
39
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030040int acpi_get_sleep_type(void)
41{
42 u16 tmp = inw(ACPI_PM1_CNT_BLK);
43 tmp = ((tmp & (7 << 10)) >> 10);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030044 return (int)tmp;
45}
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030046
47void pm_write8(u8 reg, u8 value)
48{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080049 write8((void *)(PM_MMIO_BASE + reg), value);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030050}
51
52u8 pm_read8(u8 reg)
53{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080054 return read8((void *)(PM_MMIO_BASE + reg));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030055}
56
57void pm_write16(u8 reg, u16 value)
58{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080059 write16((void *)(PM_MMIO_BASE + reg), value);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030060}
61
62u16 pm_read16(u16 reg)
63{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080064 return read16((void *)(PM_MMIO_BASE + reg));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030065}
66
67void hudson_enable(device_t dev)
68{
69 printk(BIOS_DEBUG, "hudson_enable()\n");
70 switch (dev->path.pci.devfn) {
71 case (0x14 << 3) | 7: /* 0:14.7 SD */
72 if (dev->enabled == 0) {
73 // read the VENDEV ID
74 device_t sd_dev = dev_find_slot( 0, PCI_DEVFN( 0x14, 7));
75 u32 sd_device_id = pci_read_config32( sd_dev, 0) >> 16;
76 /* turn off the SDHC controller in the PM reg */
77 u8 reg8;
78 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
79 reg8 = pm_read8(0xe7);
80 reg8 &= ~(1 << 0);
81 pm_write8(0xe7, reg8);
82 }
83 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
84 reg8 = pm_read8(0xe8);
85 reg8 &= ~(1 << 0);
86 pm_write8(0xe8, reg8);
87 }
88 /* remove device 0:14.7 from PCI space */
89 reg8 = pm_read8(0xd3);
90 reg8 &= ~(1 << 6);
91 pm_write8(0xd3, reg8);
92 }
93 break;
94 default:
95 break;
96 }
97}
98
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030099static void hudson_init_acpi_ports(void)
100{
101 /* We use some of these ports in SMM regardless of whether or not
102 * ACPI tables are generated. Enable these ports indiscriminately.
103 */
104
105 pm_write16(0x60, ACPI_PM_EVT_BLK);
106 pm_write16(0x62, ACPI_PM1_CNT_BLK);
107 pm_write16(0x64, ACPI_PM_TMR_BLK);
108 pm_write16(0x68, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -0600109 /* CpuControl is in \_PR.CP00, 6 bytes */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300110 pm_write16(0x66, ACPI_CPU_CONTROL);
111
112 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
113 pm_write16(0x6a, ACPI_SMI_CTL_PORT);
114 hudson_enable_acpi_cmd_smi();
115 } else {
116 pm_write16(0x6a, 0);
117 }
118
119 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
120 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
121 */
122 pm_write8(0x74, 1<<0 | 1<<1 | 1<<4 | 1<<2);
123}
124
125static void hudson_init(void *chip_info)
126{
127 hudson_init_acpi_ports();
128}
129
130static void hudson_final(void *chip_info)
131{
WANG Siyuanc7667f02015-06-23 22:28:17 +0800132#if IS_ENABLED(CONFIG_HUDSON_IMC_FWM)
133 agesawrapper_fchecfancontrolservice();
134#if !IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE)
135 enable_imc_thermal_zone();
136#endif
137#endif
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300138}
139
Dave Frodinbc21a412015-01-19 11:40:38 -0700140struct chip_operations southbridge_amd_pi_hudson_ops = {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300141 CHIP_NAME("ATI HUDSON")
142 .enable_dev = hudson_enable,
143 .init = hudson_init,
144 .final = hudson_final
145};