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 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 33 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 34 | int acpi_get_sleep_type(void) |
| 35 | { |
| 36 | u16 tmp = inw(ACPI_PM1_CNT_BLK); |
| 37 | tmp = ((tmp & (7 << 10)) >> 10); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 38 | return (int)tmp; |
| 39 | } |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 40 | |
| 41 | void pm_write8(u8 reg, u8 value) |
| 42 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 43 | write8((void *)(PM_MMIO_BASE + reg), value); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | u8 pm_read8(u8 reg) |
| 47 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 48 | return read8((void *)(PM_MMIO_BASE + reg)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void pm_write16(u8 reg, u16 value) |
| 52 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 53 | write16((void *)(PM_MMIO_BASE + reg), value); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | u16 pm_read16(u16 reg) |
| 57 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | return read16((void *)(PM_MMIO_BASE + reg)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void hudson_enable(device_t dev) |
| 62 | { |
| 63 | printk(BIOS_DEBUG, "hudson_enable()\n"); |
| 64 | switch (dev->path.pci.devfn) { |
| 65 | case (0x14 << 3) | 7: /* 0:14.7 SD */ |
| 66 | if (dev->enabled == 0) { |
| 67 | // read the VENDEV ID |
| 68 | device_t sd_dev = dev_find_slot( 0, PCI_DEVFN( 0x14, 7)); |
| 69 | u32 sd_device_id = pci_read_config32( sd_dev, 0) >> 16; |
| 70 | /* turn off the SDHC controller in the PM reg */ |
| 71 | u8 reg8; |
| 72 | if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) { |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 73 | reg8 = pm_read8(PM_HUD_SD_FLASH_CTRL); |
| 74 | reg8 &= ~BIT(0); |
| 75 | pm_write8(PM_HUD_SD_FLASH_CTRL, reg8); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 76 | } |
| 77 | else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) { |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 78 | reg8 = pm_read8(PM_YANG_SD_FLASH_CTRL); |
| 79 | reg8 &= ~BIT(0); |
| 80 | pm_write8(PM_YANG_SD_FLASH_CTRL, reg8); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 81 | } |
| 82 | /* remove device 0:14.7 from PCI space */ |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 83 | reg8 = pm_read8(PM_MANUAL_RESET); |
| 84 | reg8 &= ~BIT(6); |
| 85 | pm_write8(PM_MANUAL_RESET, reg8); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 86 | } |
| 87 | break; |
| 88 | default: |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 93 | static void hudson_init_acpi_ports(void) |
| 94 | { |
| 95 | /* We use some of these ports in SMM regardless of whether or not |
| 96 | * ACPI tables are generated. Enable these ports indiscriminately. |
| 97 | */ |
| 98 | |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 99 | pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK); |
| 100 | pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK); |
| 101 | pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK); |
| 102 | pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK); |
Timothy Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 103 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 104 | pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 105 | |
| 106 | if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) { |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 107 | pm_write16(PM_ACPI_SMI_CMD, ACPI_SMI_CTL_PORT); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 108 | hudson_enable_acpi_cmd_smi(); |
| 109 | } else { |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 110 | pm_write16(PM_ACPI_SMI_CMD, 0); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers |
| 114 | * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn |
| 115 | */ |
Marc Jones | d771786 | 2017-04-09 17:55:56 -0600 | [diff] [blame^] | 116 | pm_write8(PM_ACPI_CONF, BIT(0) | BIT(1) | BIT(4) | BIT(2)); |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static void hudson_init(void *chip_info) |
| 120 | { |
| 121 | hudson_init_acpi_ports(); |
| 122 | } |
| 123 | |
| 124 | static void hudson_final(void *chip_info) |
| 125 | { |
WANG Siyuan | c7667f0 | 2015-06-23 22:28:17 +0800 | [diff] [blame] | 126 | #if IS_ENABLED(CONFIG_HUDSON_IMC_FWM) |
| 127 | agesawrapper_fchecfancontrolservice(); |
| 128 | #if !IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE) |
| 129 | enable_imc_thermal_zone(); |
| 130 | #endif |
| 131 | #endif |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 132 | } |
| 133 | |
Dave Frodin | bc21a41 | 2015-01-19 11:40:38 -0700 | [diff] [blame] | 134 | struct chip_operations southbridge_amd_pi_hudson_ops = { |
Kyösti Mälkki | e8b4da2 | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 135 | CHIP_NAME("ATI HUDSON") |
| 136 | .enable_dev = hudson_enable, |
| 137 | .init = hudson_init, |
| 138 | .final = hudson_final |
| 139 | }; |