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. |
| 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 |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 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 Frodin | bc21a41 | 2015-01-19 11:40:38 -0700 | [diff] [blame] | 36 | * polluting the namespace. |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 37 | */ |
| 38 | #define PM_MMIO_BASE 0xfed80300 |
| 39 | |
| 40 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 41 | int acpi_get_sleep_type(void) |
| 42 | { |
| 43 | u16 tmp = inw(ACPI_PM1_CNT_BLK); |
| 44 | tmp = ((tmp & (7 << 10)) >> 10); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 45 | return (int)tmp; |
| 46 | } |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 47 | |
| 48 | void pm_write8(u8 reg, u8 value) |
| 49 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 50 | write8((void *)(PM_MMIO_BASE + reg), value); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | u8 pm_read8(u8 reg) |
| 54 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 55 | return read8((void *)(PM_MMIO_BASE + reg)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void pm_write16(u8 reg, u16 value) |
| 59 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 60 | write16((void *)(PM_MMIO_BASE + reg), value); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | u16 pm_read16(u16 reg) |
| 64 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 65 | return read16((void *)(PM_MMIO_BASE + reg)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void 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älkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 100 | static 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); |
Timothy Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 110 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 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 | |
| 126 | static void hudson_init(void *chip_info) |
| 127 | { |
| 128 | hudson_init_acpi_ports(); |
| 129 | } |
| 130 | |
| 131 | static void hudson_final(void *chip_info) |
| 132 | { |
| 133 | } |
| 134 | |
Dave Frodin | bc21a41 | 2015-01-19 11:40:38 -0700 | [diff] [blame] | 135 | struct chip_operations southbridge_amd_pi_hudson_ops = { |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 136 | CHIP_NAME("ATI HUDSON") |
| 137 | .enable_dev = hudson_enable, |
| 138 | .init = hudson_init, |
| 139 | .final = hudson_final |
| 140 | }; |