Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 2 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 3 | #include <device/device.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 4 | #include <device/pci.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Marshall Dawson | 25e5401 | 2019-05-29 09:29:12 -0600 | [diff] [blame] | 6 | #include <device/pci_def.h> |
Marshall Dawson | aa67def | 2019-05-03 16:10:34 -0600 | [diff] [blame] | 7 | #include <amdblocks/sata.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 8 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 9 | |
Marshall Dawson | aa67def | 2019-05-03 16:10:34 -0600 | [diff] [blame] | 10 | void soc_enable_sata_features(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 11 | { |
Marshall Dawson | 25e5401 | 2019-05-29 09:29:12 -0600 | [diff] [blame] | 12 | u8 *ahci_ptr; |
| 13 | u32 misc_ctl, cap_cfg; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 14 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 15 | u32 temp; |
| 16 | |
| 17 | /* unlock the write-protect */ |
Marshall Dawson | 25e5401 | 2019-05-29 09:29:12 -0600 | [diff] [blame] | 18 | misc_ctl = pci_read_config32(dev, SATA_MISC_CONTROL_REG); |
| 19 | misc_ctl |= SATA_MISC_SUBCLASS_WREN; |
| 20 | pci_write_config32(dev, SATA_MISC_CONTROL_REG, misc_ctl); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 21 | |
| 22 | /* set the SATA AHCI mode to allow port expanders */ |
Marshall Dawson | 25e5401 | 2019-05-29 09:29:12 -0600 | [diff] [blame] | 23 | ahci_ptr = (u8 *)(uintptr_t)ALIGN_DOWN( |
| 24 | pci_read_config32(dev, PCI_BASE_ADDRESS_5), 256); |
| 25 | |
| 26 | cap_cfg = read32(ahci_ptr + SATA_CAPABILITIES_REG); |
| 27 | cap_cfg |= SATA_CAPABILITY_SPM; |
| 28 | write32(ahci_ptr + SATA_CAPABILITIES_REG, cap_cfg); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 29 | |
| 30 | /* lock the write-protect */ |
Marshall Dawson | 25e5401 | 2019-05-29 09:29:12 -0600 | [diff] [blame] | 31 | temp = pci_read_config32(dev, SATA_MISC_CONTROL_REG); |
| 32 | temp &= ~SATA_MISC_SUBCLASS_WREN; |
| 33 | pci_write_config32(dev, SATA_MISC_CONTROL_REG, temp); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 34 | }; |