blob: ad62e51a68319a807d92e7451938377c6ddbd70b [file] [log] [blame]
Mariusz Szafranskia4041332017-08-02 17:28:17 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 - 2009 coresystems GmbH
5 * Copyright (C) 2014 - 2017 Intel Corporation.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020020#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24
25#include <soc/pci_devs.h>
26#include <soc/ramstage.h>
27#include <soc/sata.h>
28
29#include "chip.h"
30
31static void sata_init(struct device *dev)
32{
33 u32 reg32;
34 u16 reg16;
35 u32 abar;
36
37 /* Get the chip configuration */
38 config_t *config = dev->chip_info;
39
40 printk(BIOS_DEBUG, "SATA: Initializing...\n");
41
42 if (config == NULL) {
43 printk(BIOS_ERR, "SATA: ERROR: Device not in devicetree.cb!\n");
44 return;
45 }
46
47 /* SATA configuration is handled by the FSP */
48
49 /* Enable BARs */
50 pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER |
51 PCI_COMMAND_MEMORY |
52 PCI_COMMAND_IO);
53
54 printk(BIOS_DEBUG, "SATA: Controller in AHCI mode.\n");
55
56 /* Set the controller mode */
57 reg16 = pci_read_config16(dev, SATA_MAP);
58 reg16 &= ~(3 << 6);
59 reg16 |= SATA_MAP_AHCI;
60 pci_write_config16(dev, SATA_MAP, reg16);
61
62 /* Initialize AHCI memory-mapped space */
63 abar = pci_read_config32(dev, PCI_BASE_ADDRESS_5);
64 printk(BIOS_DEBUG, "ABAR: %08X\n", abar);
65
66 /* Enable AHCI Mode */
67 reg32 = read32((void *)(abar + 0x04));
68 reg32 |= (1 << 31);
69 write32((void *)(abar + 0x04), reg32);
70}
71
Elyes HAOUAS2ec41832018-05-27 17:40:58 +020072static void sata_enable(struct device *dev) { /* TODO */ }
Mariusz Szafranskia4041332017-08-02 17:28:17 +020073
74static struct device_operations sata_ops = {
75 .read_resources = pci_dev_read_resources,
76 .set_resources = pci_dev_set_resources,
77 .enable_resources = pci_dev_enable_resources,
78 .init = sata_init,
79 .enable = sata_enable,
80 .scan_bus = 0,
81 .ops_pci = &soc_pci_ops,
82};
83
84static const unsigned short pci_device_ids[] = {
85 AHCI_DEVID, /* DVN SATA AHCI */
86 AHCI2_DEVID, /* DVN SATA2 AHCI */
87 0
88};
89
90static const struct pci_driver soc_sata __pci_driver = {
91 .ops = &sata_ops,
92 .vendor = PCI_VENDOR_ID_INTEL,
93 .devices = pci_device_ids,
94};