Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 1 | /* |
| 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älkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 18 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 20 | #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 | |
| 31 | static void sata_init(struct device *dev) |
| 32 | { |
| 33 | u32 reg32; |
| 34 | u16 reg16; |
| 35 | u32 abar; |
| 36 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 37 | printk(BIOS_DEBUG, "SATA: Initializing...\n"); |
| 38 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 39 | /* SATA configuration is handled by the FSP */ |
| 40 | |
| 41 | /* Enable BARs */ |
| 42 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | |
| 43 | PCI_COMMAND_MEMORY | |
| 44 | PCI_COMMAND_IO); |
| 45 | |
| 46 | printk(BIOS_DEBUG, "SATA: Controller in AHCI mode.\n"); |
| 47 | |
| 48 | /* Set the controller mode */ |
| 49 | reg16 = pci_read_config16(dev, SATA_MAP); |
| 50 | reg16 &= ~(3 << 6); |
| 51 | reg16 |= SATA_MAP_AHCI; |
| 52 | pci_write_config16(dev, SATA_MAP, reg16); |
| 53 | |
| 54 | /* Initialize AHCI memory-mapped space */ |
| 55 | abar = pci_read_config32(dev, PCI_BASE_ADDRESS_5); |
| 56 | printk(BIOS_DEBUG, "ABAR: %08X\n", abar); |
| 57 | |
| 58 | /* Enable AHCI Mode */ |
| 59 | reg32 = read32((void *)(abar + 0x04)); |
| 60 | reg32 |= (1 << 31); |
| 61 | write32((void *)(abar + 0x04), reg32); |
| 62 | } |
| 63 | |
Elyes HAOUAS | 2ec4183 | 2018-05-27 17:40:58 +0200 | [diff] [blame] | 64 | static void sata_enable(struct device *dev) { /* TODO */ } |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 65 | |
| 66 | static struct device_operations sata_ops = { |
| 67 | .read_resources = pci_dev_read_resources, |
| 68 | .set_resources = pci_dev_set_resources, |
| 69 | .enable_resources = pci_dev_enable_resources, |
| 70 | .init = sata_init, |
| 71 | .enable = sata_enable, |
| 72 | .scan_bus = 0, |
| 73 | .ops_pci = &soc_pci_ops, |
| 74 | }; |
| 75 | |
| 76 | static const unsigned short pci_device_ids[] = { |
Felix Singer | dbc90df | 2019-11-22 00:10:20 +0100 | [diff] [blame^] | 77 | PCI_DEVICE_ID_INTEL_DENVERTON_SATA_AHCI_1, |
| 78 | PCI_DEVICE_ID_INTEL_DENVERTON_SATA_AHCI_2, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 79 | 0 |
| 80 | }; |
| 81 | |
| 82 | static const struct pci_driver soc_sata __pci_driver = { |
| 83 | .ops = &sata_ops, |
| 84 | .vendor = PCI_VENDOR_ID_INTEL, |
| 85 | .devices = pci_device_ids, |
| 86 | }; |