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