blob: e5382b410db47b255adf7922b274ccbfd5c2b9d1 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21
22#include <arch/io.h>
23#include <arch/acpi.h>
24
25#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
28#include <device/pci_ops.h>
29#include <cbmem.h>
30#include "hudson.h"
31#include "smbus.h"
32#include "smi.h"
33
34/* Offsets from ACPI_MMIO_BASE
35 * This is defined by AGESA, but we don't include AGESA headers to avoid
Dave Frodinbc21a412015-01-19 11:40:38 -070036 * polluting the namespace.
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030037 */
38#define PM_MMIO_BASE 0xfed80300
39
40
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030041int acpi_get_sleep_type(void)
42{
43 u16 tmp = inw(ACPI_PM1_CNT_BLK);
44 tmp = ((tmp & (7 << 10)) >> 10);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030045 return (int)tmp;
46}
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030047
48void pm_write8(u8 reg, u8 value)
49{
50 write8(PM_MMIO_BASE + reg, value);
51}
52
53u8 pm_read8(u8 reg)
54{
55 return read8(PM_MMIO_BASE + reg);
56}
57
58void pm_write16(u8 reg, u16 value)
59{
60 write16(PM_MMIO_BASE + reg, value);
61}
62
63u16 pm_read16(u16 reg)
64{
65 return read16(PM_MMIO_BASE + reg);
66}
67
68void hudson_enable(device_t dev)
69{
70 printk(BIOS_DEBUG, "hudson_enable()\n");
71 switch (dev->path.pci.devfn) {
72 case (0x14 << 3) | 7: /* 0:14.7 SD */
73 if (dev->enabled == 0) {
74 // read the VENDEV ID
75 device_t sd_dev = dev_find_slot( 0, PCI_DEVFN( 0x14, 7));
76 u32 sd_device_id = pci_read_config32( sd_dev, 0) >> 16;
77 /* turn off the SDHC controller in the PM reg */
78 u8 reg8;
79 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
80 reg8 = pm_read8(0xe7);
81 reg8 &= ~(1 << 0);
82 pm_write8(0xe7, reg8);
83 }
84 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
85 reg8 = pm_read8(0xe8);
86 reg8 &= ~(1 << 0);
87 pm_write8(0xe8, reg8);
88 }
89 /* remove device 0:14.7 from PCI space */
90 reg8 = pm_read8(0xd3);
91 reg8 &= ~(1 << 6);
92 pm_write8(0xd3, reg8);
93 }
94 break;
95 default:
96 break;
97 }
98}
99
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300100static void hudson_init_acpi_ports(void)
101{
102 /* We use some of these ports in SMM regardless of whether or not
103 * ACPI tables are generated. Enable these ports indiscriminately.
104 */
105
106 pm_write16(0x60, ACPI_PM_EVT_BLK);
107 pm_write16(0x62, ACPI_PM1_CNT_BLK);
108 pm_write16(0x64, ACPI_PM_TMR_BLK);
109 pm_write16(0x68, ACPI_GPE0_BLK);
110 /* CpuControl is in \_PR.CPU0, 6 bytes */
111 pm_write16(0x66, ACPI_CPU_CONTROL);
112
113 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
114 pm_write16(0x6a, ACPI_SMI_CTL_PORT);
115 hudson_enable_acpi_cmd_smi();
116 } else {
117 pm_write16(0x6a, 0);
118 }
119
120 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
121 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
122 */
123 pm_write8(0x74, 1<<0 | 1<<1 | 1<<4 | 1<<2);
124}
125
126static void hudson_init(void *chip_info)
127{
128 hudson_init_acpi_ports();
129}
130
131static void hudson_final(void *chip_info)
132{
133}
134
Dave Frodinbc21a412015-01-19 11:40:38 -0700135struct chip_operations southbridge_amd_pi_hudson_ops = {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300136 CHIP_NAME("ATI HUDSON")
137 .enable_dev = hudson_enable,
138 .init = hudson_init,
139 .final = hudson_final
140};