zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 13 | */ |
| 14 | |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 15 | #include <device/device.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 16 | #include <device/pci.h> |
| 17 | #include <device/pci_ids.h> |
| 18 | #include <device/pci_ops.h> |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 19 | |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 20 | #include "hudson.h" |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 21 | |
| 22 | static void sata_init(struct device *dev) |
| 23 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 24 | #if CONFIG(SOUTHBRIDGE_AMD_AGESA_YANGTZE) |
Bruce Griffith | 37a1d6c | 2013-07-23 11:50:12 -0600 | [diff] [blame] | 25 | /************************************** |
| 26 | * Configure the SATA port multiplier * |
| 27 | **************************************/ |
| 28 | #define BYTE_TO_DWORD_OFFSET(x) (x/4) |
| 29 | #define AHCI_BASE_ADDRESS_REG 0x24 |
| 30 | #define MISC_CONTROL_REG 0x40 |
| 31 | #define UNLOCK_BIT (1<<0) |
| 32 | #define SATA_CAPABILITIES_REG 0xFC |
| 33 | #define CFG_CAP_SPM (1<<12) |
| 34 | |
| 35 | volatile u32 *ahci_ptr = |
Stefan Reinauer | 772029f | 2015-07-30 16:23:50 -0700 | [diff] [blame] | 36 | (u32*)(uintptr_t)(pci_read_config32(dev, AHCI_BASE_ADDRESS_REG) & 0xFFFFFF00); |
Bruce Griffith | 37a1d6c | 2013-07-23 11:50:12 -0600 | [diff] [blame] | 37 | u32 temp; |
| 38 | |
| 39 | /* unlock the write-protect */ |
| 40 | temp = pci_read_config32(dev, MISC_CONTROL_REG); |
| 41 | temp |= UNLOCK_BIT; |
| 42 | pci_write_config32(dev, MISC_CONTROL_REG, temp); |
| 43 | |
| 44 | /* set the SATA AHCI mode to allow port expanders */ |
| 45 | *(ahci_ptr + BYTE_TO_DWORD_OFFSET(SATA_CAPABILITIES_REG)) |= CFG_CAP_SPM; |
| 46 | |
| 47 | /* lock the write-protect */ |
| 48 | temp = pci_read_config32(dev, MISC_CONTROL_REG); |
| 49 | temp &= ~UNLOCK_BIT; |
| 50 | pci_write_config32(dev, MISC_CONTROL_REG, temp); |
| 51 | #endif |
| 52 | }; |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 53 | |
| 54 | static struct pci_operations lops_pci = { |
| 55 | /* .set_subsystem = pci_dev_set_subsystem, */ |
| 56 | }; |
| 57 | |
| 58 | static struct device_operations sata_ops = { |
| 59 | .read_resources = pci_dev_read_resources, |
| 60 | .set_resources = pci_dev_set_resources, |
| 61 | .enable_resources = pci_dev_enable_resources, |
| 62 | .init = sata_init, |
| 63 | .scan_bus = 0, |
| 64 | .ops_pci = &lops_pci, |
| 65 | }; |
| 66 | |
| 67 | static const struct pci_driver sata0_driver __pci_driver = { |
| 68 | .ops = &sata_ops, |
| 69 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 70 | .device = PCI_DEVICE_ID_AMD_SB900_SATA, |
zbao | 246e84b | 2012-07-13 18:47:03 +0800 | [diff] [blame] | 71 | }; |
Siyuan Wang | 9157145 | 2013-07-09 17:32:42 +0800 | [diff] [blame] | 72 | |
| 73 | static const struct pci_driver sata0_driver_ahci __pci_driver = { |
| 74 | .ops = &sata_ops, |
| 75 | .vendor = PCI_VENDOR_ID_AMD, |
Kyösti Mälkki | 9d9a552 | 2016-11-19 22:14:59 +0200 | [diff] [blame] | 76 | .device = PCI_DEVICE_ID_AMD_SB900_SATA_AHCI, |
Siyuan Wang | 9157145 | 2013-07-09 17:32:42 +0800 | [diff] [blame] | 77 | }; |