zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [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 | |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 33 | /* Offsets from ACPI_MMIO_BASE |
| 34 | * This is defined by AGESA, but we don't include AGESA headers to avoid |
| 35 | * polluting the namesace. |
| 36 | */ |
| 37 | #define PM_MMIO_BASE 0xfed80300 |
| 38 | |
| 39 | |
Stefan Reinauer | 8ada152 | 2012-11-16 13:34:48 -0800 | [diff] [blame] | 40 | #if CONFIG_HAVE_ACPI_RESUME |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 41 | int acpi_get_sleep_type(void) |
| 42 | { |
Alexandru Gagniuc | cf1f9b6 | 2014-04-20 13:24:42 -0500 | [diff] [blame] | 43 | u16 tmp = inw(ACPI_PM1_CNT_BLK); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 44 | tmp = ((tmp & (7 << 10)) >> 10); |
| 45 | /* printk(BIOS_DEBUG, "SLP_TYP type was %x\n", tmp); */ |
| 46 | return (int)tmp; |
| 47 | } |
| 48 | #endif |
| 49 | |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 50 | void backup_top_of_ram(uint64_t ramtop) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 51 | { |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 52 | u32 dword = (u32) ramtop; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 53 | int nvram_pos = 0xf8, i; /* temp */ |
| 54 | /* printk(BIOS_DEBUG, "dword=%x\n", dword); */ |
| 55 | for (i = 0; i<4; i++) { |
| 56 | /* printk(BIOS_DEBUG, "nvram_pos=%x, dword>>(8*i)=%x\n", nvram_pos, (dword >>(8 * i)) & 0xff); */ |
| 57 | outb(nvram_pos, BIOSRAM_INDEX); |
| 58 | outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA); |
| 59 | nvram_pos++; |
| 60 | } |
| 61 | } |
| 62 | |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 63 | void pm_write8(u8 reg, u8 value) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 64 | { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 65 | write8(PM_MMIO_BASE + reg, value); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 66 | } |
| 67 | |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 68 | u8 pm_read8(u8 reg) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 69 | { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 70 | return read8(PM_MMIO_BASE + reg); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 71 | } |
| 72 | |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 73 | void pm_write16(u8 reg, u16 value) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 74 | { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 75 | write16(PM_MMIO_BASE + reg, value); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 76 | } |
| 77 | |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 78 | u16 pm_read16(u16 reg) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 79 | { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 80 | return read16(PM_MMIO_BASE + reg); |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 81 | } |
| 82 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 83 | void hudson_enable(device_t dev) |
| 84 | { |
Martin Roth | f5726ea | 2013-01-18 12:55:40 -0700 | [diff] [blame] | 85 | printk(BIOS_DEBUG, "hudson_enable()\n"); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 86 | switch (dev->path.pci.devfn) { |
| 87 | case (0x14 << 3) | 7: /* 0:14.7 SD */ |
| 88 | if (dev->enabled == 0) { |
| 89 | // read the VENDEV ID |
| 90 | device_t sd_dev = dev_find_slot( 0, PCI_DEVFN( 0x14, 7)); |
| 91 | u32 sd_device_id = pci_read_config32( sd_dev, 0) >> 16; |
| 92 | /* turn off the SDHC controller in the PM reg */ |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 93 | u8 reg8; |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 94 | if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 95 | reg8 = pm_read8(0xe7); |
| 96 | reg8 &= ~(1 << 0); |
| 97 | pm_write8(0xe7, reg8); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 98 | } |
| 99 | else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 100 | reg8 = pm_read8(0xe8); |
| 101 | reg8 &= ~(1 << 0); |
| 102 | pm_write8(0xe8, reg8); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 103 | } |
| 104 | /* remove device 0:14.7 from PCI space */ |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 105 | reg8 = pm_read8(0xd3); |
| 106 | reg8 &= ~(1 << 6); |
| 107 | pm_write8(0xd3, reg8); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 108 | } |
| 109 | break; |
| 110 | default: |
| 111 | break; |
| 112 | } |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 113 | } |
| 114 | |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 115 | #if CONFIG_HAVE_ACPI_RESUME |
| 116 | unsigned long get_top_of_ram(void) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 117 | { |
| 118 | uint32_t xdata = 0; |
| 119 | int xnvram_pos = 0xf8, xi; |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 120 | if (acpi_get_sleep_type() != 3) |
| 121 | return 0; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 122 | for (xi = 0; xi<4; xi++) { |
| 123 | outb(xnvram_pos, BIOSRAM_INDEX); |
| 124 | xdata &= ~(0xff << (xi * 8)); |
| 125 | xdata |= inb(BIOSRAM_DATA) << (xi *8); |
| 126 | xnvram_pos++; |
| 127 | } |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 128 | return (unsigned long) xdata; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 129 | } |
Kyösti Mälkki | bc90e15 | 2013-09-04 13:26:11 +0300 | [diff] [blame] | 130 | #endif |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 131 | |
| 132 | struct chip_operations southbridge_amd_agesa_hudson_ops = { |
| 133 | CHIP_NAME("ATI HUDSON") |
| 134 | .enable_dev = hudson_enable, |
| 135 | }; |