Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 1 | /* |
| 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älkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 14 | */ |
| 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 Siyuan | c7667f0 | 2015-06-23 22:28:17 +0800 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_HUDSON_IMC_FWM) |
| 30 | #include "fchec.h" |
| 31 | #endif |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 32 | |
| 33 | /* Offsets from ACPI_MMIO_BASE |
| 34 | * This is defined by AGESA, but we don't include AGESA headers to avoid |
Dave Frodin | bc21a41 | 2015-01-19 11:40:38 -0700 | [diff] [blame] | 35 | * polluting the namespace. |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 36 | */ |
| 37 | #define PM_MMIO_BASE 0xfed80300 |
| 38 | |
| 39 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 40 | int acpi_get_sleep_type(void) |
| 41 | { |
| 42 | u16 tmp = inw(ACPI_PM1_CNT_BLK); |
| 43 | tmp = ((tmp & (7 << 10)) >> 10); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 44 | return (int)tmp; |
| 45 | } |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 46 | |
| 47 | void pm_write8(u8 reg, u8 value) |
| 48 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 49 | write8((void *)(PM_MMIO_BASE + reg), value); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | u8 pm_read8(u8 reg) |
| 53 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 54 | return read8((void *)(PM_MMIO_BASE + reg)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void pm_write16(u8 reg, u16 value) |
| 58 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 59 | write16((void *)(PM_MMIO_BASE + reg), value); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | u16 pm_read16(u16 reg) |
| 63 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 64 | return read16((void *)(PM_MMIO_BASE + reg)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void 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älkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 99 | static 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 Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 109 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 110 | 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 | |
| 125 | static void hudson_init(void *chip_info) |
| 126 | { |
| 127 | hudson_init_acpi_ports(); |
| 128 | } |
| 129 | |
| 130 | static void hudson_final(void *chip_info) |
| 131 | { |
WANG Siyuan | c7667f0 | 2015-06-23 22:28:17 +0800 | [diff] [blame] | 132 | #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älkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 138 | } |
| 139 | |
Dave Frodin | bc21a41 | 2015-01-19 11:40:38 -0700 | [diff] [blame] | 140 | struct chip_operations southbridge_amd_pi_hudson_ops = { |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 141 | CHIP_NAME("ATI HUDSON") |
| 142 | .enable_dev = hudson_enable, |
| 143 | .init = hudson_init, |
| 144 | .final = hudson_final |
| 145 | }; |