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