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. |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 14 | */ |
| 15 | |
Michał Żygowski | f3db2ae | 2019-11-24 13:26:10 +0100 | [diff] [blame^] | 16 | #include <amdblocks/acpimmio.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 17 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 18 | #include <device/mmio.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Kyösti Mälkki | 0bc06ab | 2018-05-20 15:41:05 +0300 | [diff] [blame] | 21 | #include <device/pci_def.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 22 | #include <device/pci_ids.h> |
| 23 | #include <device/pci_ops.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 24 | #include "hudson.h" |
Kyösti Mälkki | 29d9c56 | 2014-10-16 21:35:48 +0300 | [diff] [blame] | 25 | #include "imc.h" |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 26 | #include "smbus.h" |
Alexandru Gagniuc | 86777e3 | 2014-04-20 14:36:29 -0500 | [diff] [blame] | 27 | #include "smi.h" |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 28 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 29 | |
Alexandru Gagniuc | d2e5f68 | 2014-04-16 16:33:03 -0500 | [diff] [blame] | 30 | #define PM_REG_USB_ENABLE 0xef |
| 31 | |
| 32 | enum usb_enable { |
| 33 | USB_EN_DEVFN_12_0 = (1 << 0), |
| 34 | USB_EN_DEVFN_12_2 = (1 << 1), |
| 35 | USB_EN_DEVFN_13_0 = (1 << 2), |
| 36 | USB_EN_DEVFN_13_2 = (1 << 3), |
| 37 | USB_EN_DEVFN_16_0 = (1 << 4), |
| 38 | USB_EN_DEVFN_16_2 = (1 << 5), |
| 39 | }; |
| 40 | |
| 41 | static void hudson_disable_usb(u8 disable) |
| 42 | { |
| 43 | u8 reg8; |
| 44 | |
| 45 | /* Bit 7 handles routing, 6 is reserved. we don't mess with those */ |
| 46 | disable &= 0x3f; |
| 47 | |
| 48 | reg8 = pm_read8(PM_REG_USB_ENABLE); |
| 49 | reg8 &= ~disable; |
| 50 | pm_write8(PM_REG_USB_ENABLE, reg8); |
| 51 | } |
| 52 | |
Elyes HAOUAS | a93e754 | 2018-05-19 14:30:47 +0200 | [diff] [blame] | 53 | void hudson_enable(struct device *dev) |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 54 | { |
Martin Roth | f5726ea | 2013-01-18 12:55:40 -0700 | [diff] [blame] | 55 | printk(BIOS_DEBUG, "hudson_enable()\n"); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 56 | switch (dev->path.pci.devfn) { |
Tobias Diedrich | ae3adff | 2014-11-08 00:38:33 +0100 | [diff] [blame] | 57 | case PCI_DEVFN(0x14, 5): |
| 58 | if (dev->enabled == 0) { |
Kyösti Mälkki | 0bc06ab | 2018-05-20 15:41:05 +0300 | [diff] [blame] | 59 | u32 usb_device_id = pci_read_config16(dev, PCI_DEVICE_ID); |
Tobias Diedrich | ae3adff | 2014-11-08 00:38:33 +0100 | [diff] [blame] | 60 | u8 reg8; |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 61 | if (usb_device_id == PCI_DEVICE_ID_AMD_SB900_USB_20_5) { |
Tobias Diedrich | ae3adff | 2014-11-08 00:38:33 +0100 | [diff] [blame] | 62 | /* turn off and remove device 0:14.5 from PCI space */ |
| 63 | reg8 = pm_read8(0xef); |
| 64 | reg8 &= ~(1 << 6); |
| 65 | pm_write8(0xef, reg8); |
| 66 | } |
| 67 | } |
| 68 | break; |
| 69 | |
Alexandru Gagniuc | d2e5f68 | 2014-04-16 16:33:03 -0500 | [diff] [blame] | 70 | case PCI_DEVFN(0x14, 7): |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 71 | if (dev->enabled == 0) { |
Kyösti Mälkki | 0bc06ab | 2018-05-20 15:41:05 +0300 | [diff] [blame] | 72 | u32 sd_device_id = pci_read_config16(dev, PCI_DEVICE_ID); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 73 | /* turn off the SDHC controller in the PM reg */ |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 74 | u8 reg8; |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 75 | if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 76 | reg8 = pm_read8(0xe7); |
| 77 | reg8 &= ~(1 << 0); |
| 78 | pm_write8(0xe7, reg8); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 79 | } |
| 80 | else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) { |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 81 | reg8 = pm_read8(0xe8); |
| 82 | reg8 &= ~(1 << 0); |
| 83 | pm_write8(0xe8, reg8); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 84 | } |
| 85 | /* remove device 0:14.7 from PCI space */ |
Alexandru Gagniuc | 342ac64 | 2014-04-14 16:44:19 -0500 | [diff] [blame] | 86 | reg8 = pm_read8(0xd3); |
| 87 | reg8 &= ~(1 << 6); |
| 88 | pm_write8(0xd3, reg8); |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 89 | } |
| 90 | break; |
Alexandru Gagniuc | d2e5f68 | 2014-04-16 16:33:03 -0500 | [diff] [blame] | 91 | |
| 92 | /* Make sure to disable other functions if function 0 is disabled */ |
| 93 | case PCI_DEVFN(0x12, 0): |
| 94 | if (dev->enabled == 0) |
| 95 | hudson_disable_usb(USB_EN_DEVFN_12_0); |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 96 | /* fall through */ |
| 97 | case PCI_DEVFN(0x12, 2): |
Alexandru Gagniuc | d2e5f68 | 2014-04-16 16:33:03 -0500 | [diff] [blame] | 98 | if (dev->enabled == 0) |
| 99 | hudson_disable_usb(USB_EN_DEVFN_12_2); |
| 100 | break; |
| 101 | case PCI_DEVFN(0x13, 0): |
| 102 | if (dev->enabled == 0) |
| 103 | hudson_disable_usb(USB_EN_DEVFN_13_0); |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 104 | /* fall through */ |
| 105 | case PCI_DEVFN(0x13, 2): |
Alexandru Gagniuc | d2e5f68 | 2014-04-16 16:33:03 -0500 | [diff] [blame] | 106 | if (dev->enabled == 0) |
| 107 | hudson_disable_usb(USB_EN_DEVFN_13_2); |
| 108 | break; |
| 109 | case PCI_DEVFN(0x16, 0): |
| 110 | if (dev->enabled == 0) |
| 111 | hudson_disable_usb(USB_EN_DEVFN_16_0); |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 112 | /* fall through */ |
| 113 | case PCI_DEVFN(0x16, 2): |
Alexandru Gagniuc | d2e5f68 | 2014-04-16 16:33:03 -0500 | [diff] [blame] | 114 | if (dev->enabled == 0) |
| 115 | hudson_disable_usb(USB_EN_DEVFN_16_2); |
| 116 | break; |
Dave Frodin | ea90963 | 2013-05-31 08:15:57 -0600 | [diff] [blame] | 117 | default: |
| 118 | break; |
| 119 | } |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 120 | } |
| 121 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 122 | |
Alexandru Gagniuc | 86777e3 | 2014-04-20 14:36:29 -0500 | [diff] [blame] | 123 | static void hudson_init_acpi_ports(void) |
| 124 | { |
| 125 | /* We use some of these ports in SMM regardless of whether or not |
| 126 | * ACPI tables are generated. Enable these ports indiscriminately. |
| 127 | */ |
| 128 | |
| 129 | pm_write16(0x60, ACPI_PM_EVT_BLK); |
| 130 | pm_write16(0x62, ACPI_PM1_CNT_BLK); |
| 131 | pm_write16(0x64, ACPI_PM_TMR_BLK); |
| 132 | pm_write16(0x68, ACPI_GPE0_BLK); |
Timothy Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 133 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
Alexandru Gagniuc | 86777e3 | 2014-04-20 14:36:29 -0500 | [diff] [blame] | 134 | pm_write16(0x66, ACPI_CPU_CONTROL); |
| 135 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 136 | if (CONFIG(HAVE_SMI_HANDLER)) { |
Alexandru Gagniuc | 86777e3 | 2014-04-20 14:36:29 -0500 | [diff] [blame] | 137 | pm_write16(0x6a, ACPI_SMI_CTL_PORT); |
| 138 | hudson_enable_acpi_cmd_smi(); |
| 139 | } else { |
| 140 | pm_write16(0x6a, 0); |
| 141 | } |
| 142 | |
| 143 | /* AcpiDecodeEnable, When set, SB uses the contents of the PM registers |
| 144 | * at index 60-6B to decode ACPI I/O address. AcpiSmiEn & SmiCmdEn |
| 145 | */ |
| 146 | pm_write8(0x74, 1<<0 | 1<<1 | 1<<4 | 1<<2); |
| 147 | } |
| 148 | |
| 149 | static void hudson_init(void *chip_info) |
| 150 | { |
| 151 | hudson_init_acpi_ports(); |
| 152 | } |
| 153 | |
Kyösti Mälkki | 29d9c56 | 2014-10-16 21:35:48 +0300 | [diff] [blame] | 154 | static void hudson_final(void *chip_info) |
| 155 | { |
Kyösti Mälkki | 29d9c56 | 2014-10-16 21:35:48 +0300 | [diff] [blame] | 156 | /* AMD AGESA does not enable thermal zone, so we enable it here. */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 157 | if (CONFIG(HUDSON_IMC_FWM) && |
| 158 | !CONFIG(ACPI_ENABLE_THERMAL_ZONE)) |
Kyösti Mälkki | eb064b3 | 2017-08-24 21:20:10 +0300 | [diff] [blame] | 159 | enable_imc_thermal_zone(); |
Kyösti Mälkki | 29d9c56 | 2014-10-16 21:35:48 +0300 | [diff] [blame] | 160 | } |
| 161 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 162 | struct chip_operations southbridge_amd_agesa_hudson_ops = { |
| 163 | CHIP_NAME("ATI HUDSON") |
| 164 | .enable_dev = hudson_enable, |
Kyösti Mälkki | 29d9c56 | 2014-10-16 21:35:48 +0300 | [diff] [blame] | 165 | .init = hudson_init, |
| 166 | .final = hudson_final |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 167 | }; |