blob: c2348a963da907a38f9339beb5d8048a325a0391 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
zbao246e84b2012-07-13 18:47:03 +08002
zbao246e84b2012-07-13 18:47:03 +08003#include <device/device.h>
zbao246e84b2012-07-13 18:47:03 +08004#include <device/pci.h>
5#include <device/pci_ids.h>
6#include <device/pci_ops.h>
zbao246e84b2012-07-13 18:47:03 +08007
Elyes HAOUASbf0970e2019-03-21 11:10:03 +01008#include "hudson.h"
zbao246e84b2012-07-13 18:47:03 +08009
10static void sata_init(struct device *dev)
11{
Julius Wernercd49cce2019-03-05 16:53:33 -080012#if CONFIG(SOUTHBRIDGE_AMD_AGESA_YANGTZE)
Bruce Griffith37a1d6c2013-07-23 11:50:12 -060013 /**************************************
14 * Configure the SATA port multiplier *
15 **************************************/
16 #define BYTE_TO_DWORD_OFFSET(x) (x/4)
17 #define AHCI_BASE_ADDRESS_REG 0x24
18 #define MISC_CONTROL_REG 0x40
19 #define UNLOCK_BIT (1<<0)
20 #define SATA_CAPABILITIES_REG 0xFC
21 #define CFG_CAP_SPM (1<<12)
22
23 volatile u32 *ahci_ptr =
Stefan Reinauer772029f2015-07-30 16:23:50 -070024 (u32*)(uintptr_t)(pci_read_config32(dev, AHCI_BASE_ADDRESS_REG) & 0xFFFFFF00);
Bruce Griffith37a1d6c2013-07-23 11:50:12 -060025 u32 temp;
26
27 /* unlock the write-protect */
28 temp = pci_read_config32(dev, MISC_CONTROL_REG);
29 temp |= UNLOCK_BIT;
30 pci_write_config32(dev, MISC_CONTROL_REG, temp);
31
32 /* set the SATA AHCI mode to allow port expanders */
33 *(ahci_ptr + BYTE_TO_DWORD_OFFSET(SATA_CAPABILITIES_REG)) |= CFG_CAP_SPM;
34
35 /* lock the write-protect */
36 temp = pci_read_config32(dev, MISC_CONTROL_REG);
37 temp &= ~UNLOCK_BIT;
38 pci_write_config32(dev, MISC_CONTROL_REG, temp);
39#endif
40};
zbao246e84b2012-07-13 18:47:03 +080041
42static struct pci_operations lops_pci = {
43 /* .set_subsystem = pci_dev_set_subsystem, */
44};
45
46static struct device_operations sata_ops = {
47 .read_resources = pci_dev_read_resources,
48 .set_resources = pci_dev_set_resources,
49 .enable_resources = pci_dev_enable_resources,
50 .init = sata_init,
zbao246e84b2012-07-13 18:47:03 +080051 .ops_pci = &lops_pci,
52};
53
54static const struct pci_driver sata0_driver __pci_driver = {
55 .ops = &sata_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010056 .vendor = PCI_VID_AMD,
57 .device = PCI_DID_AMD_SB900_SATA,
zbao246e84b2012-07-13 18:47:03 +080058};
Siyuan Wang91571452013-07-09 17:32:42 +080059
60static const struct pci_driver sata0_driver_ahci __pci_driver = {
61 .ops = &sata_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010062 .vendor = PCI_VID_AMD,
63 .device = PCI_DID_AMD_SB900_SATA_AHCI,
Siyuan Wang91571452013-07-09 17:32:42 +080064};