blob: 3fb5d75c324cd5bbf6709604772780ab976ad52b [file] [log] [blame]
Angel Pons80d92382020-04-05 15:47:00 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Mariusz Szafranskia4041332017-08-02 17:28:17 +02002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +02005#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
16static void sata_init(struct device *dev)
17{
18 u32 reg32;
Mariusz Szafranskia4041332017-08-02 17:28:17 +020019 u32 abar;
20
Mariusz Szafranskia4041332017-08-02 17:28:17 +020021 printk(BIOS_DEBUG, "SATA: Initializing...\n");
22
Mariusz Szafranskia4041332017-08-02 17:28:17 +020023 /* 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 Douthit2c18ba52019-08-02 17:05:03 -040033 reg32 = pci_read_config32(dev, SATAGC);
34 reg32 &= ~SATAGC_AHCI;
35 pci_write_config32(dev, SATAGC, reg32);
Mariusz Szafranskia4041332017-08-02 17:28:17 +020036
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 HAOUAS2ec41832018-05-27 17:40:58 +020047static void sata_enable(struct device *dev) { /* TODO */ }
Mariusz Szafranskia4041332017-08-02 17:28:17 +020048
49static 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 Szafranskia4041332017-08-02 17:28:17 +020055 .ops_pci = &soc_pci_ops,
56};
57
58static const unsigned short pci_device_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010059 PCI_DID_INTEL_DNV_SATA_AHCI_1,
60 PCI_DID_INTEL_DNV_SATA_AHCI_2,
Mariusz Szafranskia4041332017-08-02 17:28:17 +020061 0
62};
63
64static const struct pci_driver soc_sata __pci_driver = {
65 .ops = &sata_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010066 .vendor = PCI_VID_INTEL,
Mariusz Szafranskia4041332017-08-02 17:28:17 +020067 .devices = pci_device_ids,
68};