blob: af1095c8194902fe85c007e258bcb169e4d3feb5 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
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
16#include <console/console.h>
17
18#include <arch/io.h>
19#include <arch/acpi.h>
Marshall Dawson8a906df2017-06-13 14:19:02 -060020#include <bootstate.h>
Marc Jones24484842017-05-04 21:17:45 -060021
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <device/pci_ops.h>
26#include <cbmem.h>
Marshall Dawson8a906df2017-06-13 14:19:02 -060027#include <amd_pci_util.h>
Marc Jones24484842017-05-04 21:17:45 -060028#include <soc/hudson.h>
29#include <soc/smbus.h>
30#include <soc/smi.h>
31#if IS_ENABLED(CONFIG_STONEYRIDGE_IMC_FWM)
32#include <fchec.h>
33#endif
34
35
36int acpi_get_sleep_type(void)
37{
38 u16 tmp = inw(ACPI_PM1_CNT_BLK);
39 tmp = ((tmp & (7 << 10)) >> 10);
40 return (int)tmp;
41}
42
43void pm_write8(u8 reg, u8 value)
44{
45 write8((void *)(PM_MMIO_BASE + reg), value);
46}
47
48u8 pm_read8(u8 reg)
49{
50 return read8((void *)(PM_MMIO_BASE + reg));
51}
52
53void pm_write16(u8 reg, u16 value)
54{
55 write16((void *)(PM_MMIO_BASE + reg), value);
56}
57
58u16 pm_read16(u16 reg)
59{
60 return read16((void *)(PM_MMIO_BASE + reg));
61}
62
63void hudson_enable(device_t dev)
64{
65 printk(BIOS_DEBUG, "hudson_enable()\n");
66 switch (dev->path.pci.devfn) {
67 case (0x14 << 3) | 7: /* 0:14.7 SD */
68 if (dev->enabled == 0) {
69 // read the VENDEV ID
Marshall Dawson4e101ad2017-06-15 12:17:38 -060070 device_t sd_dev = dev_find_slot(0, PCI_DEVFN(0x14, 7));
71 u32 sd_device_id = pci_read_config32(sd_dev, 0) >> 16;
Marc Jones24484842017-05-04 21:17:45 -060072 /* turn off the SDHC controller in the PM reg */
73 u8 reg8;
74 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
75 reg8 = pm_read8(PM_HUD_SD_FLASH_CTRL);
76 reg8 &= ~BIT(0);
77 pm_write8(PM_HUD_SD_FLASH_CTRL, reg8);
Marshall Dawson4e101ad2017-06-15 12:17:38 -060078 } else if (sd_device_id
79 == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
Marc Jones24484842017-05-04 21:17:45 -060080 reg8 = pm_read8(PM_YANG_SD_FLASH_CTRL);
81 reg8 &= ~BIT(0);
82 pm_write8(PM_YANG_SD_FLASH_CTRL, reg8);
83 }
84 /* remove device 0:14.7 from PCI space */
85 reg8 = pm_read8(PM_MANUAL_RESET);
86 reg8 &= ~BIT(6);
87 pm_write8(PM_MANUAL_RESET, reg8);
88 }
89 break;
90 default:
91 break;
92 }
93}
94
95static void hudson_init_acpi_ports(void)
96{
97 /* We use some of these ports in SMM regardless of whether or not
98 * ACPI tables are generated. Enable these ports indiscriminately.
99 */
100
101 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
102 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
103 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
104 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
105 /* CpuControl is in \_PR.CP00, 6 bytes */
106 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
107
108 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
109 pm_write16(PM_ACPI_SMI_CMD, ACPI_SMI_CTL_PORT);
110 hudson_enable_acpi_cmd_smi();
111 } else {
112 pm_write16(PM_ACPI_SMI_CMD, 0);
113 }
114
115 /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers
116 * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn
117 */
118 pm_write8(PM_ACPI_CONF, BIT(0) | BIT(1) | BIT(4) | BIT(2));
119}
120
121void hudson_init(void *chip_info)
122{
123 hudson_init_acpi_ports();
124}
125
126void hudson_final(void *chip_info)
127{
128#if IS_ENABLED(CONFIG_STONEYRIDGE_IMC_FWM)
129 agesawrapper_fchecfancontrolservice();
130#if !IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE)
131 enable_imc_thermal_zone();
132#endif
133#endif
134}
Marshall Dawson8a906df2017-06-13 14:19:02 -0600135
136/*
137 * Update the PCI devices with a valid IRQ number
138 * that is set in the mainboard PCI_IRQ structures.
139 */
140static void set_pci_irqs(void *unused)
141{
142 /* Write PCI_INTR regs 0xC00/0xC01 */
143 write_pci_int_table();
144
145 /* Write IRQs for all devicetree enabled devices */
146 write_pci_cfg_irqs();
147}
148
149/*
150 * Hook this function into the PCI state machine
151 * on entry into BS_DEV_ENABLE.
152 */
153BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);