Angel Pons | 80d9238 | 2020-04-05 15:47:00 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
| 8 | #include <device/pci_ids.h> |
| 9 | |
| 10 | #include <soc/pci_devs.h> |
| 11 | #include <soc/ramstage.h> |
| 12 | #include <soc/sata.h> |
| 13 | |
| 14 | #include "chip.h" |
| 15 | |
| 16 | static void sata_init(struct device *dev) |
| 17 | { |
| 18 | u32 reg32; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 19 | u32 abar; |
| 20 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 21 | printk(BIOS_DEBUG, "SATA: Initializing...\n"); |
| 22 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 23 | /* SATA configuration is handled by the FSP */ |
| 24 | |
| 25 | /* Enable BARs */ |
| 26 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | |
| 27 | PCI_COMMAND_MEMORY | |
| 28 | PCI_COMMAND_IO); |
| 29 | |
| 30 | printk(BIOS_DEBUG, "SATA: Controller in AHCI mode.\n"); |
| 31 | |
| 32 | /* Set the controller mode */ |
Stephen Douthit | 2c18ba5 | 2019-08-02 17:05:03 -0400 | [diff] [blame] | 33 | reg32 = pci_read_config32(dev, SATAGC); |
| 34 | reg32 &= ~SATAGC_AHCI; |
| 35 | pci_write_config32(dev, SATAGC, reg32); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 36 | |
| 37 | /* Initialize AHCI memory-mapped space */ |
| 38 | abar = pci_read_config32(dev, PCI_BASE_ADDRESS_5); |
| 39 | printk(BIOS_DEBUG, "ABAR: %08X\n", abar); |
| 40 | |
| 41 | /* Enable AHCI Mode */ |
| 42 | reg32 = read32((void *)(abar + 0x04)); |
| 43 | reg32 |= (1 << 31); |
| 44 | write32((void *)(abar + 0x04), reg32); |
| 45 | } |
| 46 | |
Elyes HAOUAS | 2ec4183 | 2018-05-27 17:40:58 +0200 | [diff] [blame] | 47 | static void sata_enable(struct device *dev) { /* TODO */ } |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 48 | |
| 49 | static struct device_operations sata_ops = { |
| 50 | .read_resources = pci_dev_read_resources, |
| 51 | .set_resources = pci_dev_set_resources, |
| 52 | .enable_resources = pci_dev_enable_resources, |
| 53 | .init = sata_init, |
| 54 | .enable = sata_enable, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 55 | .ops_pci = &soc_pci_ops, |
| 56 | }; |
| 57 | |
| 58 | static const unsigned short pci_device_ids[] = { |
Jeff Daly | 2a81cab | 2022-01-06 16:32:11 -0500 | [diff] [blame] | 59 | PCI_DEVICE_ID_INTEL_DNV_SATA_AHCI_1, |
| 60 | PCI_DEVICE_ID_INTEL_DNV_SATA_AHCI_2, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 61 | 0 |
| 62 | }; |
| 63 | |
| 64 | static const struct pci_driver soc_sata __pci_driver = { |
| 65 | .ops = &sata_ops, |
| 66 | .vendor = PCI_VENDOR_ID_INTEL, |
| 67 | .devices = pci_device_ids, |
| 68 | }; |