blob: bd9deb135bf2c784568cf38c1efa3bdea61fc915 [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#include "fchec.h"
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030030
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030031int acpi_get_sleep_type(void)
32{
33 u16 tmp = inw(ACPI_PM1_CNT_BLK);
34 tmp = ((tmp & (7 << 10)) >> 10);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030035 return (int)tmp;
36}
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030037
38void pm_write8(u8 reg, u8 value)
39{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080040 write8((void *)(PM_MMIO_BASE + reg), value);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030041}
42
43u8 pm_read8(u8 reg)
44{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080045 return read8((void *)(PM_MMIO_BASE + reg));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030046}
47
48void pm_write16(u8 reg, u16 value)
49{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080050 write16((void *)(PM_MMIO_BASE + reg), value);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030051}
52
53u16 pm_read16(u16 reg)
54{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 return read16((void *)(PM_MMIO_BASE + reg));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030056}
57
Elyes HAOUASd9ef5462018-05-19 17:08:23 +020058void hudson_enable(struct device *dev)
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030059{
60 printk(BIOS_DEBUG, "hudson_enable()\n");
61 switch (dev->path.pci.devfn) {
Kyösti Mälkkib11d4e32018-05-20 10:39:10 +030062 case PCI_DEVFN(0x14, 7): /* SD */
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030063 if (dev->enabled == 0) {
Kyösti Mälkkib11d4e32018-05-20 10:39:10 +030064 u32 sd_device_id = pci_read_config32(dev, 0) >> 16;
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030065 /* turn off the SDHC controller in the PM reg */
66 u8 reg8;
67 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060068 reg8 = pm_read8(PM_HUD_SD_FLASH_CTRL);
69 reg8 &= ~BIT(0);
70 pm_write8(PM_HUD_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030071 }
72 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
Marc Jonesd7717862017-04-09 17:55:56 -060073 reg8 = pm_read8(PM_YANG_SD_FLASH_CTRL);
74 reg8 &= ~BIT(0);
75 pm_write8(PM_YANG_SD_FLASH_CTRL, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030076 }
77 /* remove device 0:14.7 from PCI space */
Marc Jonesd7717862017-04-09 17:55:56 -060078 reg8 = pm_read8(PM_MANUAL_RESET);
79 reg8 &= ~BIT(6);
80 pm_write8(PM_MANUAL_RESET, reg8);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030081 }
82 break;
83 default:
84 break;
85 }
86}
87
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +030088static void hudson_init_acpi_ports(void)
89{
90 /* We use some of these ports in SMM regardless of whether or not
91 * ACPI tables are generated. Enable these ports indiscriminately.
92 */
93
Marc Jonesd7717862017-04-09 17:55:56 -060094 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
95 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
96 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
97 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
Timothy Pearson033bb4b2015-02-10 22:21:39 -060098 /* CpuControl is in \_PR.CP00, 6 bytes */
Marc Jonesd7717862017-04-09 17:55:56 -060099 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300100
101 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
Marc Jonesd7717862017-04-09 17:55:56 -0600102 pm_write16(PM_ACPI_SMI_CMD, ACPI_SMI_CTL_PORT);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300103 hudson_enable_acpi_cmd_smi();
104 } else {
Marc Jonesd7717862017-04-09 17:55:56 -0600105 pm_write16(PM_ACPI_SMI_CMD, 0);
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300106 }
107
108 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
109 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
110 */
Marc Jonesd7717862017-04-09 17:55:56 -0600111 pm_write8(PM_ACPI_CONF, BIT(0) | BIT(1) | BIT(4) | BIT(2));
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300112}
113
114static void hudson_init(void *chip_info)
115{
116 hudson_init_acpi_ports();
117}
118
119static void hudson_final(void *chip_info)
120{
Kyösti Mälkkieb064b32017-08-24 21:20:10 +0300121 if (IS_ENABLED(CONFIG_HUDSON_IMC_FWM)) {
122 agesawrapper_fchecfancontrolservice();
123 if (!IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE))
124 enable_imc_thermal_zone();
125 }
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300126}
127
Dave Frodinbc21a412015-01-19 11:40:38 -0700128struct chip_operations southbridge_amd_pi_hudson_ops = {
Kyösti Mälkkie8b4da22014-10-21 18:22:32 +0300129 CHIP_NAME("ATI HUDSON")
130 .enable_dev = hudson_enable,
131 .init = hudson_init,
132 .final = hudson_final
133};